Skip to content

package: web-fs #10396

Open
Open
@ryanflorence

Description

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);

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status

    Planned

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions