Open soapdog opened 3 years ago
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)
}
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.
@soapdog Did you ever get this fixed? I have the same problem using 1.4.3 from npm.
@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.
@soapdog
Does it work when using the latest dev build of BrowserFS? (you will need to build from source)
Please use https://github.com/zen-fs/core/issues/20
I have a filesystem initialized with
I can read and write normally to
/tmp
and read from/templates
but attempts to write using eitherwriteFileSync
orwriteFile
to any of the IndexedDB paths fail with error: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.