Skip to content

fs: add FileHandle.prototype.readableStream()#39331

Closed
jasnell wants to merge 3 commits intonodejs:masterfrom
jasnell:filehandle-webstream
Closed

fs: add FileHandle.prototype.readableStream()#39331
jasnell wants to merge 3 commits intonodejs:masterfrom
jasnell:filehandle-webstream

Conversation

@jasnell
Copy link
Copy Markdown
Member

@jasnell jasnell commented Jul 9, 2021

Builds on #39134 (the first commit is from that PR)

Adds an experimental readableStream() method to FileHandle objects that returns ReadableStream.

const file = await fs.promises.open('./some/file/to/read');

for await (const chunk of file.readableStream())
  console.log(chunk);
const file = await fs.promises.open('./some/file/to/read');

const readable = file.readableStream();
const reader = readable.getReader();
reader.read().then(console.log);

Note that the ReadableStream returned is affected by the other methods for reading the FileHandle data. For instance, if file.readFile() is called first, the ReadableStream will not return any data.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. lib / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants