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

package: web-fs #10396

Open
ryanflorence opened this issue Jan 8, 2025 · 0 comments
Open

package: web-fs #10396

ryanflorence opened this issue Jan 8, 2025 · 0 comments
Assignees
Milestone

Comments

@ryanflorence
Copy link
Member

ryanflorence commented Jan 8, 2025

This is a fs implementation that uses Web APIs instead of bespoke Node.js APIs. We don't need to port everything, just some of the most important pieces.

As a starting point, we should have createReadableStream and createWritableStream APIs that are analogous to Node's fs.createReadStream and fs.createWriteStream APIs for working with streams.

import { createReadableStream, createWritableStream } from 'web-fs';

// Read a file
let stream: ReadableStream = createReadableStream('file.txt');

// Easily write a ReadableStream to disk
let response = await fetch('http://github.com');
await response.body.pipeTo(createWritableStream('github.html'));

// Copy a file
await createReadableStream('file.txt').pipeTo(createWritableStream('file-copy.txt'));

We should also have openFile, readFile, and writeFile methods analogous to Node's (experimental) fs.openAsBlob, fs.readFile, and fs.writeFile functions, except they will be able to work with and return File objects.

import { openFile, readFile, writeFile } from 'web-fs';

let file: File = openFile('file.txt'); // sync!

let contents = await readFile('file.txt', options);

await writeFile('file-copy.txt', file);
@mjackson mjackson added this to Roadmap Jan 8, 2025
@ryanflorence ryanflorence converted this from a draft issue Jan 8, 2025
@ryanflorence ryanflorence added this to the v3 milestone Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Planned
Development

No branches or pull requests

2 participants