Skip to content

Conversation

@yagipy
Copy link

@yagipy yagipy commented Feb 23, 2021

Fixes: #37391

Checklist

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Feb 23, 2021
@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch from 93ff28b to 99cfd5d Compare February 23, 2021 10:37
@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch from 99cfd5d to b5538ff Compare February 23, 2021 11:25
@yagipy yagipy requested a review from aduh95 February 23, 2021 11:33
@Linkgoron
Copy link
Contributor

Linkgoron commented Feb 23, 2021

Currently this incorrectly handles fds that are given to it (path can be a FileHandle or a string). It tries to open them when it shouldn't and tries to close them in the end (If a FileHandle is passed into writeFile, its lifetime isn't managed by the method - i.e. it shouldn't be opened or closed)

IMO a cleaner solution would be to keep writeFile essentially the same as it is today (I think it would just need one change - changing if(!isArrayBufferView(...)) to if(!isIterable(...) && !isArrayBufferView(...)) , and moving the writing logic into writeFileHandle. This would also remove and simplify some code, because you won't have to manage the lifetime of the handle.

@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch 2 times, most recently from 31b0e54 to a5b5162 Compare February 23, 2021 14:48
@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch from a5b5162 to c85ea4d Compare February 23, 2021 15:05
@yagipy
Copy link
Author

yagipy commented Feb 23, 2021

@Linkgoron @aduh95
Thanks for reviewing it.

IMO a cleaner solution would be to keep writeFile essentially the same as it is today (I think it would just need one change - changing if(!isArrayBufferView(...)) to if(!isIterable(...) && !isArrayBufferView(...)) , and moving the writing logic into writeFileHandle. This would also remove and simplify some code, because you won't have to manage the lifetime of the handle.

I reimplemented it in the above direction.

@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch from c85ea4d to 08b77e5 Compare February 23, 2021 15:34
@yagipy yagipy requested a review from aduh95 February 23, 2021 15:47
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add an entry in the YAML changes list to document the change?

@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch from 08b77e5 to 3e95264 Compare February 24, 2021 00:21
@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch from 3e95264 to 4c51e71 Compare February 24, 2021 00:25
@yagipy yagipy requested a review from aduh95 February 24, 2021 02:37
@yagipy yagipy force-pushed the fs-writefile-fix-data-argument branch 2 times, most recently from 6a2feca to e880436 Compare February 24, 2021 16:21
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot!

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 24, 2021
@nodejs-github-bot
Copy link
Collaborator

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. fs Issues and PRs related to the fs subsystem / file system. 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.

writeFile support AsyncIterable, Iterable & Stream as data argument

7 participants