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

writeFile support AsyncIterable, Iterable & Stream as data argument #37391

Closed
ronag opened this issue Feb 16, 2021 · 7 comments
Closed

writeFile support AsyncIterable, Iterable & Stream as data argument #37391

ronag opened this issue Feb 16, 2021 · 7 comments
Labels
fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors.

Comments

@ronag
Copy link
Member

ronag commented Feb 16, 2021

https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback

@ronag ronag added fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors. labels Feb 16, 2021
@ronag ronag changed the title writeFile should take AsyncIterable, Iterable & Stream as data argument writeFile should take AsyncIterable, Iterable & Stream as data argument Feb 16, 2021
@ronag ronag changed the title writeFile should take AsyncIterable, Iterable & Stream as data argument writeFile support AsyncIterable, Iterable & Stream as data argument Feb 16, 2021
@ronag
Copy link
Member Author

ronag commented Feb 16, 2021

Writing an iterable, async iterable and stream can be done something like this:

const fsp = require('fs/promises')
const fileHandle = await fsp.open(filePath, flags)
try {
  for await (const buf of data) {
    if (signal?.aborted) {
      throw new AbortedError()
    }
    await fileHandle.write(buf)
  }
} finally {
  await fileHandle.close()
}

You could make a special version for stream which has better performance.

@yagipy
Copy link
Contributor

yagipy commented Feb 16, 2021

I would like to work on this problem.

@yagipy
Copy link
Contributor

yagipy commented Feb 19, 2021

@ronag
Does this issue include internal implementation?

Or is it just a doc fix like the PR below?
yagipy#1

@ronag
Copy link
Member Author

ronag commented Feb 19, 2021

It requires internal implementation.

@hyagihashi-cq
Copy link

@ronag
OK.

Is it like this image?
スクリーンショット 2021-02-19 22 02 58

@ronag
Copy link
Member Author

ronag commented Feb 19, 2021

yes, maybe it is already implemented? I didn't know.

@hyagihashi-cq
Copy link

This is the code that I am implementing locally.

I will continue with the implementation.

yagipy pushed a commit to yagipy/node that referenced this issue Feb 21, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 21, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 21, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 22, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 23, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 23, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 23, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 23, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 23, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 23, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 23, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 24, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 24, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 24, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 24, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 28, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Feb 28, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 3, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 3, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 3, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 4, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 4, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 4, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 5, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 6, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 20, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 20, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Mar 28, 2021
yagipy pushed a commit to yagipy/node that referenced this issue Apr 3, 2021
@aduh95 aduh95 closed this as completed in 4958091 Apr 4, 2021
MylesBorins pushed a commit that referenced this issue Apr 4, 2021
Fixes: #37391

PR-URL: #37490
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Apr 5, 2021
Fixes: #37391

PR-URL: #37490
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
aduh95 pushed a commit to aduh95/node that referenced this issue Sep 1, 2021
Fixes: nodejs#37391

PR-URL: nodejs#37490
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
aduh95 pushed a commit to aduh95/node that referenced this issue Sep 1, 2021
Fixes: nodejs#37391

PR-URL: nodejs#37490
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit that referenced this issue Sep 4, 2021
Fixes: #37391

PR-URL: #37490
Backport-PR-URL: #39973
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants