Skip to content

Commit

Permalink
chore(driver): zenfs
Browse files Browse the repository at this point in the history
  • Loading branch information
atty303 committed May 16, 2024
1 parent 54bd851 commit 4b47031
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/driver/src/js/nodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ export const createNODEFS = (fs, FS, PATH, ERRNO_CODES) => {
var path = NODEFS.realPath(node);
NODEFS.tryFSOperation(() => {
if (FS.isDir(node.mode)) {
console.log("mkdirSync", path, node.mode);
fs.mkdirSync(path, node.mode);
} else {
console.log("writeFileSync", path, "", { mode: node.mode });
fs.writeFileSync(path, "", { mode: node.mode });
}
});
Expand Down Expand Up @@ -235,13 +237,15 @@ export const createNODEFS = (fs, FS, PATH, ERRNO_CODES) => {
NODEFS.tryFSOperation(() => {
if (FS.isFile(stream.node.mode)) {
stream.shared.refcount = 1;
console.log("openSync", path, NODEFS.flagsForNode(stream.flags));
stream.nfd = fs.openSync(path, NODEFS.flagsForNode(stream.flags));
}
});
},
close(stream) {
NODEFS.tryFSOperation(() => {
if (FS.isFile(stream.node.mode) && stream.nfd && --stream.shared.refcount === 0) {
console.log("closeSync", stream.nfd);
fs.closeSync(stream.nfd);
}
});
Expand All @@ -255,6 +259,7 @@ export const createNODEFS = (fs, FS, PATH, ERRNO_CODES) => {
return NODEFS.tryFSOperation(() => {
// fs.readSync(stream.nfd, new Int8Array(buffer.buffer, offset, length), 0, length, position),
const buf = new Int8Array(length);
// console.log("readSync", 0, length, position);
const bytesRead = fs.readSync(stream.nfd, buf, 0, length, position);
buffer.set(buf, offset);
return bytesRead;
Expand All @@ -264,8 +269,9 @@ export const createNODEFS = (fs, FS, PATH, ERRNO_CODES) => {
return NODEFS.tryFSOperation(() => {
// fs.writeSync(stream.nfd, new Int8Array(buffer.buffer, offset, length), 0, length, position),
if (length === 0) return 0;
const buf = new ArrayBuffer(length);
const buf = new Uint8Array(length);
buf.set(buffer.subarray(offset, offset + length));
console.log("write", 0, length, position);
// console.log("write", new TextDecoder().decode(buf));
return fs.writeSync(stream.nfd, buf, 0, length, position);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/driver/src/js/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ export class DriverWorker {
// name: "root.zip",
// } as any);

const userFs = await zenfs.resolveMountConfig({
name: "LocalStorage",
backend: zenfs.Port,
port: self as unknown as any,
});
// const userFs = await zenfs.resolveMountConfig({
// name: "LocalStorage",
// backend: zenfs.Port,
// port: self as unknown as any,
// });

await zenfs.configure({
mounts: {
Expand Down

0 comments on commit 4b47031

Please sign in to comment.