How to keep a temporary filesystem

There’s no option yet in webnative to keep a temporary filesystem around for “a soon to be” user. So in the meantime app developers can manage that on their own in the following way.

Written for webnative version 0.23.x

Create the filesystem

const permissions = { fs: { privatePaths: [ "/" ], publicPaths: [ "/" ] } } 
const fs = await webnative.fs.empty({ localOnly: true, permissions })

// Add some content
await fs.write("/private/Databank/Food/Ingredients.json", "[]")

// Get the content identifier
const cid = await fs.root.put()

The only thing to do now is to keep that CID around somewhere locally, so next time you can …

Load the filesystem

const fs = await webnative.fs.fromCID(cid, { localOnly: true, permissions })

// []


You will not be able to load this filesystem on another browser or device. The webnative.fs.empty function generates an AES key for you and stores this locally. It needs this AES key to be able to read the files of the /private filesystem.