Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mounted IndexedDB file system doesn't support writeFileSync #315

Open
soapdog opened this issue May 16, 2021 · 6 comments
Open

Mounted IndexedDB file system doesn't support writeFileSync #315

soapdog opened this issue May 16, 2021 · 6 comments
Labels
Milestone

Comments

@soapdog
Copy link

soapdog commented May 16, 2021

I have a filesystem initialized with

BrowserFS.configure({
    fs: "MountableFileSystem",
    options: {
        "/templates": {
            fs: "ZipFS",
            options: {
                // Wrap as Buffer object.
                zipData: Buffer.from(zipData)
            }
        },
        "/tmp": { fs: "InMemory" },
        "/books": { fs: "IndexedDB", options: { storeName: "books" } },
        "/etc": { fs: "IndexedDB", options: { storeName: "etc"} },
        "/integration": { fs: "IndexedDB", options: { storeName: "integration" } }

    }
}

I can read and write normally to /tmp and read from /templates but attempts to write using either writeFileSync or writeFile to any of the IndexedDB paths fail with error:

errno: 95, code: "ENOTSUP"

I'm building with rollup, and I didn't expected this to fail. Trying to use "LocalStorage" as a backend works but since I'm writing large files, I'd rather use IndexedDB.

@soapdog
Copy link
Author

soapdog commented May 16, 2021

I've created a jsfiddle with a minimal example: https://jsfiddle.net/24vfryqs/ showing that the IndexedDB backend is not working as expected.

The source is:

try {
BrowserFS.install(window);

BrowserFS.configure(
  {
    fs: "MountableFileSystem",
    options: {
      "/tmp": { fs: "InMemory" },
      "/home": { fs: "IndexedDB", options: { storeName: "home"} },
    },
  },
  function (e) {
    if (e) {
      // An error occurred.
      console.log("error has happened", e)
      throw e
    }
    // Otherwise, BrowserFS is ready to use!
    var fs = require("fs")
    fs.writeFile(
      "/tmp/test.txt",
      "Cool, I can do this in the browser!",
      function (err) {
        fs.readFile("/tmp/test.txt", function (err, contents) {
          console.log(contents.toString())
        })
      }
    )
        
    fs.writeFile(
      "/home/test.txt",
      "Cool, I can do this in the indexeddb!",
      function (err) {
      	if (err) {
        	throw err
        }
        fs.readFile("/home/test.txt", function (err, contents) {
          console.log(contents.toString())
        })
      }
    )
  }
)
} catch(e) {
	console.log(e.message)
}

@cgc
Copy link

cgc commented Aug 30, 2021

Wonder if the issue might be because you're using version 2.0.0? 1.4.3 is the last non-beta release on NPM, and changing the fiddle's cdnjs link from 2.0.0 to 1.4.3 seems to result in correct behavior.

@mathiscode
Copy link

@soapdog Did you ever get this fixed? I have the same problem using 1.4.3 from npm.

@soapdog
Copy link
Author

soapdog commented Dec 8, 2021

@mathiscode no, I never got this to work. In the end, I realised my app could be stateless and removed all the persistence code from it. I still use BrowserFS in it, but it is all in-memory storage.

@james-pre
Copy link
Collaborator

@soapdog

Does it work when using the latest dev build of BrowserFS? (you will need to build from source)

@james-pre james-pre added the bug label Mar 9, 2023
@james-pre james-pre changed the title IndexedDB mounted file system using OverlayFS doesn't support writeFileSync Mounted IndexedDB file system doesn't support writeFileSync Sep 15, 2023
@james-pre james-pre added this to the 2.0 milestone Sep 15, 2023
@james-pre james-pre changed the title Mounted IndexedDB file system doesn't support writeFileSync Mounted IndexedDB file system doesn't support writeFileSync Oct 25, 2023
@james-pre
Copy link
Collaborator

james-pre commented Oct 25, 2023

Please use zen-fs/core#20

@james-pre james-pre closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2023
Repository owner locked and limited conversation to collaborators Oct 25, 2023
@james-pre james-pre reopened this May 17, 2024
Repository owner unlocked this conversation May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants