Closed atty303 closed 4 months ago
I'm also implementing WebStorage myself since @zenfs/dom
doesn't keep up with the latest core
. I'd be happy to have this one updated accordingly.
@atty303 @zenfs/dom
v0.2.8 has the latest core. Sorry I didn't get it out earlier.
Also, this error is worrisome. It explains why some of the Port
tests fail. They are disabled, which in the future probably shouldn't be done.
@james-pre The writing problem has been resolved! However, I still have a problem with reading. Reading after writing is normal, but reading immediately after startup returns empty.
import * as zenfs from "@zenfs/core";
import * as Comlink from "comlink";
Comlink.expose({
async main() {
await zenfs.configure({
mounts: {
"/user": {
name: "LocalStorage",
backend: zenfs.Port,
port: self as unknown as any,
},
},
});
console.log(zenfs.fs.readFileSync("/user/test.txt", "utf8"));
},
});
@atty303 I think this read after startup issue could be related to #61. I will keep track of it there and I am closing this issue since the original big has been fixed.
Thank you so much for contributing!
main.ts
worker.ts
Executing this code will cause the contents written by
writeSync
to be lost. Local storage4346683818588372979
is the content of the file but it is empty.If I re-run it here, I get an error in
crossCopy
.If you open with
w+
, you can write normally.src/emulation/sync.ts:156-167
The root cause seems to be in the code above. When the mode is
w+
,createFileSync
is called, but whenr+
,openFileSync
is called.src/filesystem.ts:361-368
In the case of
createFileSync
, theAsyncFileSystem
'screateFileSync
is executed and returns aPreloadedFile
with theAsyncFileSystem
asfs
, so it is correctly synchronized with theStore
.src/filesystem.ts:370-372
However, in the case of
openFileSync
, aPreloadedFile
withAsyncFileSystem#_sync
asfs
is returned. This is not synchronized withStore
even ifclose
is performed because the relationship withAsyncFileSystem
is severed.I was not sure how to correct it correctly, so I hope you can address this.