isomorphic-git / lightning-fs

A lean and fast 'fs' for the browser
MIT License
476 stars 47 forks source link

Native File System API #28

Open agentcooper opened 4 years ago

agentcooper commented 4 years ago

Hey. I see that some work was already done in https://github.com/isomorphic-git/lightning-fs/tree/feat/native. What is the timeline for this and what are the current blockers?

For reference: https://www.chromestatus.com/feature/6284708426022912.

billiegoose commented 4 years ago

Aha! Yes, I'm super excited about this. The current blocker is currently File handles cannot be serialized. This means they can't be sent to a Worker thread via postMessage. Which is very unfortunate, because that means you're restricted to using the main thread, which is already over burdened. All my "realistic" app architectures require using isomorphic-git and LightningFS in a worker in order to stay within performance budgets.

As soon as Chrome lands support for serializing them, I'm going to revive that branch and finish it. The other nice thing we'll be able to do is save the file handles in IndexedDb so you won't have to prompt the user with a permissions UX every time they re-open the page.

Twaha-Rahman commented 4 years ago

@wmhilton File handlers can be serialized and can be sent to a Worker thread via postMessage as of Chrome 83 😉

Capture

shd101wyy commented 3 years ago

I am currently working on a project https://github.com/0xGG/vscode-pwa and I implemented two file system providers for the vscode running on the web: One uses lightning-fs for constructing the memfs; the other one was handwritten using the native file system api.

https://github.com/0xGG/vscode-pwa also uses isomorphic-git for managing git repos. It would be great if lighting-fs can support native file system so I could better refactor my code :+1:

Thanks for the awesome project!

predmond commented 3 years ago

@wmhilton any updates/progress on the native branch?

danperks commented 1 year ago

As a rudimentary solution, you can load the files manually via the File System API into LightingFS with a simple function like this one:

async function loadFiles(fs, folder, path = "/") {
  for await (const entry of folder.values()) {
  if (entry.kind === "file") {
      // Create the file
      await fs.promises.writeFile(path + entry.name, await entry.getFile());
    }
    if (entry.kind === "directory") {
      // Create the folder, then run on all files within
      await fs.promises.mkdir(path + entry.name)
      await convertFolder(entry, setRows, path + entry.name + "/");
    }
}