microbit-foundation / microbit-fs

A TypeScript library to manipulate the micro:bit MicroPython filesystem.
https://microbit-foundation.github.io/microbit-fs/
MIT License
12 stars 1 forks source link

Directly load and inspect a HEX with a filesystem #45

Open CSharperMantle opened 3 months ago

CSharperMantle commented 3 months ago

I am new to this package so feel free to correct me at any point :D

Currently the docs says that to construct a class MicropythonFsHex, we need a plain MicroPython HEX image without a filesystem. That being said, if we need to inspect the filesystem a given HEX image with a filesystem already included, we need yet another HEX image with no filesystem, load that first, then import the HEX-to-inspect into the loaded image.

Is there a shortcut? From the importing feature I think this package has complete features already present to inspect filesystems in a HEX string. Perhaps exposing such a direct-inspect API would be of more convenient to at least a fraction of users.


After a bit of digging the internals I have found that there are indeed functions present and documented as said above, like this:

https://github.com/microbit-foundation/microbit-fs/blob/8b4343c251a18b2feb7867d10bfcc428dd9657fe/src/micropython-fs-builder.ts#L461-L475

However these are not exported in index.ts:

https://github.com/microbit-foundation/microbit-fs/blob/8b4343c251a18b2feb7867d10bfcc428dd9657fe/src/index.ts#L1-L3

Adding a single line will solve this issue, but it will add a lot of public APIs to the module. Still, given that all these functions have been properly documented, it could still be a reasonable choice.