natevw / fatfs

Standalone FAT16/FAT32 filesystem implementation in JavaScript
47 stars 13 forks source link

Can fatfs be used with files emulating memory? #32

Closed tawjaw closed 3 years ago

tawjaw commented 4 years ago

Hello

I’m wondering if this library can be used to read and write to a file. The goal is for the file to simulate an SD card.

I’d appreciate any tips. Thanks

natevw commented 3 years ago

Yes, see the Volume Driver API section of the documentation. The example there with the exports.createDriverSync might work as-is for you — give it a local path to basically a raw "disk image" and it should work.

I think the only caveats are that the file needs to already be a particular size, and should already be formatted. Right now this library doesn't include a method to format a partition but it wouldn't be too hard to add. See the link at https://github.com/natevw/fatfs/issues/30#issuecomment-528057718 where another project is using this with in-memory buffers; it looks like they've worked out some code of their own to format (which would be a bit simpler if it could use some internal stuff of this library directly).

Hope that helps! I'll close this out as I think you have some pointers to what you need but feel free to re-open and/or post followups in the thread here.