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

WebAccess TypeError on write #28

Open
Seanw265 opened this issue Jan 31, 2025 · 1 comment
Open

WebAccess TypeError on write #28

Seanw265 opened this issue Jan 31, 2025 · 1 comment
Assignees
Labels
needs more info More information is needed to confirm or diagnose the issue

Comments

@Seanw265
Copy link

WebAccessFS throws a type error on writeFileSync:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'buffer')

Here is a minimal reproduction of the issue:

Link to runnable example

import { configureSingle, fs } from "@zenfs/core";
import { WebAccess } from "@zenfs/dom";

console.log("clearing opfs");
await (await navigator.storage.getDirectory()).remove({ recursive: true });

const opfsRoot = await navigator.storage.getDirectory();

console.log("configuring");
await configureSingle({
  backend: WebAccess,
  handle: opfsRoot,
});
console.log("configured");

console.log("reading /", fs.readdirSync("/"));
try {
  console.log("writing /hello-world.txt");
  fs.writeFileSync("/hello-world.txt", "Hello world from provider worker!");
} catch (error) {
  console.error("Error writing /hello-world", error);
}
console.log("reading /", fs.readdirSync("/"));

The odd thing in this example is that the file does indeed seem to be written.

Here's the output I get:

'clearing opfs'
'configuring'
'configured'
'reading /' []
'writing /hello-world.txt'
Error writing /hello-world
'reading /' [ 'hello-world.txt' ]
@Seanw265
Copy link
Author

Hmm something odd is that switching the writeFileSync for a writeFile with a callback results in no TypeError, but in this case, the file doesn't seem to be written at all. Running readdirSync after the write completes shows an empty directory.

link to example

@james-pre james-pre self-assigned this Feb 1, 2025
@james-pre james-pre added the needs more info More information is needed to confirm or diagnose the issue label Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is needed to confirm or diagnose the issue
Projects
None yet
Development

No branches or pull requests

2 participants