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

Asyncronous File System API #5317

Closed
oyiptong opened this issue May 14, 2020 · 1 comment
Closed

Asyncronous File System API #5317

oyiptong opened this issue May 14, 2020 · 1 comment
Labels
duplicate a duplicate of another issue

Comments

@oyiptong
Copy link

Consider implementing an asynchronous file system API.

On the Web, the Native File System API implements an API surface that provides file and directory access.

A similar API shape for asynchronous file access would be great for interop between server/command-line and web code.

The API has a shape that allows streaming to a file, creating new files, opening an existing file, cloberring or not, iterating through directories, etc.

Adapted from the explainer, here's an example:

const dir_ref = ... // Some mechanism to obtain a directory handle TBD.

for await (const [name, entry] of dir_ref) {
    // Iterate through a directory.
    // entry is a FileSystemFileHandle or a FileSystemDirectoryHandle.
    // name is equal to entry.name
}

const new_file = await dir_ref.getFile('foo.txt', {create: true}); // Create a file.

// Write to a file using an API resembling something like pwrite.
const new_file_writer = await new_file.createWritable();
await new_file_writer.write(await file_ref.getFile());
await new_file_writer.close();

// Or using streams.
const file_ref = await dir_ref.getFile('foo.js'); // Get a file from a directory.
const copy2 = await dir_ref.getFile('foo2.txt', {create: true});
(await file_ref.getFile()).stream().pipeTo(await copy2.createWritable());
...
@bartlomieju bartlomieju added feat new feature (which has been agreed to/accepted) web related to Web APIs labels May 15, 2020
@josephrocca
Copy link
Contributor

I think this is a duplicate of #2456?

@kitsonk kitsonk added duplicate a duplicate of another issue and removed feat new feature (which has been agreed to/accepted) web related to Web APIs labels Sep 24, 2020
@kitsonk kitsonk closed this as completed Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants