GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: allow overring fs for streams by ronag · Pull Request #29083 · nodejs/node

Conversation

@ronag

@ronag ronag commented Aug 11, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This would allow modules such as graceful-fs to gracefully implement alternative fs methods for fs streams.

Would also make it possible for user land modules to implement alternative file systems (e.g. WebDAV, HTTP, SMB etc...) while re-using the existing streams implementation.

Refs: #29050

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss and addaleax reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to file-system APIs and the fs module. label Aug 11, 2019
@ronag ronag mentioned this pull request Aug 11, 2019
fs: deprecate file stream open #29061
Closed
4 tasks done
@ronag
ronag force-pushed the fs-stream-fs branch 2 times, most recently from e7563b2 to 4846e3f Compare August 11, 2019 15:38
addaleax
addaleax reviewed Aug 12, 2019
View reviewed changes
Comment thread lib/internal/fs/streams.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax added the semver-minor PRs that contain new features and should be released in the next minor version. label Aug 12, 2019
@jasnell

jasnell commented Aug 13, 2019

Copy link
Copy Markdown
Member

We have been moving in the opposite direction for many apis... Making them more difficult or impossible to monkey patch for both maintenance and security reasons. I'm not sure this pr is the right approach. We should revisit or strategy around this and build better hook points that are safer and supportable.

addaleax reacted with confused emoji
All reactions
  • 😕 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell previously requested changes Aug 13, 2019
View reviewed changes

@jasnell jasnell left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Making the -1 explicit until this can be discussed further

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ChALkeR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@ronag

ronag commented Aug 13, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@jasnell: I get your point but I think I disagree. This is more about composition than encapsulation. We are allowing the user to pass a public API interface. For me this is no different than letting users create their on read and write streams using Readable and Writable.

e.g. graceful-fs, rather than rolling their own implementation they chose to monkey patch. Which is something we should discourage, but still we need to provide reasonable alternatives.

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag

ronag commented Aug 13, 2019

Copy link
Copy Markdown
Member Author

I'll fix @addaleax comments once there is consensus.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Aug 13, 2019

Copy link
Copy Markdown
Member

@jasnell I don’t think it qualifies as monkey-patching if we provide a public API for overriding methods. In my opinion this is exactly the kind of approach we should take in order to avoid monkey-patching.

/cc @nodejs/tsc

coreyfarrell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina

mcollina commented Aug 13, 2019

Copy link
Copy Markdown
Member

I’m not convinced that there is so much code in WriteStream or ReadStream that can’t easily be duplicated in a module, if one desired so. I’m unsure if this would solve the graceful-fs problems or not.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coreyfarrell

coreyfarrell commented Aug 13, 2019

Copy link
Copy Markdown
Member

Right now graceful-fs creates new ES5 object constructors which create objects that extend fs.ReadStream and fs.WriteStream with an overridden open method to enable retry on ENFILE/EMFILE. Even this little change means that the overridden open method can (does) diverge from the node.js method. The native WrtieStream in node.js 5.5.0+ supports an autoClose: false option to prevent stream.destroy() from being called when fs.open has an error. graceful-fs currently performs an unconditional stream.destroy() upon error from fs.open in WriteStream.prototype.open. I think completely re-implementing the fs streams code in graceful-fs would lead to more chances of undocumented differences from native fs. Obviously graceful-fs is meant to be different from native fs, but only in the documented ways.

This change would allow graceful-fs to skip re-implementing the stream open methods if run under node.js 13+, it would be able to just inject the fs option to the constructor instead.

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Aug 13, 2019

Copy link
Copy Markdown
Member

As opposed to overriding like this or monkeypatching, what I'd prefer to see is the improved ability for developers to create their own alternative implementations using supported lower level APIs... Something more along the lines of...

class MyAlternativeWriter extends fs.FileWriteBase {
  open() { /* ... */ }
  close() { /* ... */ }
  /* ... */
}

While the differences in the approaches may be subtle, this would allow anyone inspecting the object and seeing the MyAlternativeWriter object name to know that they are working with something that operates differently from fs.FileWriter.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell reviewed Aug 13, 2019
View reviewed changes
Comment thread lib/internal/fs/streams.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell reviewed Aug 13, 2019
View reviewed changes
Comment thread test/parallel/test-fs-write-stream-fs.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell reviewed Aug 13, 2019
View reviewed changes
Comment thread test/parallel/test-fs-read-stream.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronag
ronag force-pushed the fs-stream-fs branch 3 times, most recently from aa36717 to 752a5b2 Compare August 14, 2019 08:27
This was referenced Aug 14, 2019
Semver-major changes isaacs/node-graceful-fs#173
Closed
[x] fs: refactor to fully use Stream api #29048
Closed
@ronag
ronag force-pushed the fs-stream-fs branch from 752a5b2 to 12c3893 Compare August 14, 2019 17:58
addaleax
addaleax previously approved these changes Aug 14, 2019
View reviewed changes

@addaleax addaleax left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ftr, I liked the previous approach (passing an fs object), but it doesn’t make a huge difference anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/api/fs.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/internal/fs/streams.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronag
ronag force-pushed the fs-stream-fs branch from 12c3893 to 0869dd0 Compare August 14, 2019 19:21
@ronag

ronag commented Aug 14, 2019

Copy link
Copy Markdown
Member Author

Ftr, I liked the previous approach (passing an fs object), but it doesn’t make a huge difference anyway.

I'm fine with either...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ChALkeR
ChALkeR reviewed Aug 14, 2019
View reviewed changes
Comment thread package-lock.json Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ChALkeR

ChALkeR commented Aug 14, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@jasnell I don't think this is monkey-patching, it is introducing an API so that monkey-patching wouldn't be used. That API would be documented and its usage would be visible. Also, we could just forbid this call with policies or harden method later, security-wise.

In general, I am in favour (if this would help to minimize monkey-patching), but I am not sure about the API yet and I don't think that open/read/close is enough here? But that's not a blocker.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag
ronag force-pushed the fs-stream-fs branch from 0869dd0 to 8e47c7e Compare August 14, 2019 19:52
@coreyfarrell

coreyfarrell commented Aug 14, 2019

Copy link
Copy Markdown
Member

Ftr, I liked the previous approach (passing an fs object), but it doesn’t make a huge difference anyway.

I do agree with @jasnell that having the stream internally store references to the individual methods is best so the stream ignores any monkey-patching done after construction but I think it would be simpler for the public API to just accept a single fs option. I'm not stuck on this one way or the other just sharing my preference.

With the fs option you could still test with the following:

fs.createReadStream(fn, {
  fs: {
    open: common.mustCall(fs.open),
    read: common.mustCallAtLeast(fs.read, 1),
    close: common.mustCall(fs.close)
  }
});
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ronag added 3 commits December 11, 2019 19:23
@ronag
fixup: bad rebase
5123e58
@ronag
fixup: linting
3d39786
@ronag
fixup: missing doc refs
e0cc161
@ronag
ronag force-pushed the fs-stream-fs branch from 1569d32 to f587c25 Compare December 11, 2019 18:23
@ronag

ronag commented Dec 11, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

rebased, @coreyfarrell: another CI?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag @coreyfarrell
Update doc/api/fs.md
b9f518b
Co-Authored-By: Corey Farrell <[email protected]>
@ronag
ronag force-pushed the fs-stream-fs branch from f587c25 to b9f518b Compare December 11, 2019 18:39
@nodejs-github-bot

nodejs-github-bot commented Dec 11, 2019

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/27579/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag
WIP
cdca4b7
@ronag

ronag commented Dec 12, 2019

Copy link
Copy Markdown
Member Author

@Trott: This looks ready to land?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax
addaleax reviewed Dec 12, 2019
View reviewed changes
Comment thread lib/internal/fs/streams.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronag
fixup
f3f609a
@nodejs-github-bot

nodejs-github-bot commented Dec 12, 2019

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/27601/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Dec 12, 2019
@ronag
fixup
835a02a
@ronag

ronag commented Dec 13, 2019

Copy link
Copy Markdown
Member Author

Sorry, I made a git mistake with the last one. Can we start another CI?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Dec 13, 2019

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/27610/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Dec 13, 2019

Copy link
Copy Markdown
Member

@ronag Linter is still failing…

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag

ronag commented Dec 13, 2019

Copy link
Copy Markdown
Member Author

How do I run the linter without having to rebuild the whole thing?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag
fixup: linting
be60186
@Trott

Trott commented Dec 14, 2019

Copy link
Copy Markdown
Member

How do I run the linter without having to rebuild the whole thing?

If it's just JavaScript linting, make lint-js (or vcbuild lint-js on Windows) shouldn't require a full rebuild, I don't think.

ronag reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Dec 14, 2019

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/27700/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Trott
Trott approved these changes Dec 18, 2019
View reviewed changes
@Trott

Trott commented Dec 18, 2019

Copy link
Copy Markdown
Member

(Whoever lands this should edit the commit first line for typos since those end up displayed prominently in the change log files.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Dec 18, 2019

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/27776/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Trott pushed a commit that referenced this pull request Dec 18, 2019
@ronag @Trott
fs: allow overriding fs for streams
2b9847c
Allow overriding open, write, and close when using createReadStream()
and createWriteStream().

PR-URL: #29083
Refs: #29050
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@Trott

Trott commented Dec 18, 2019

Copy link
Copy Markdown
Member

Landed in 2b9847c.

ronag, brody2consult, and coreyfarrell reacted with hooray emoji
All reactions
  • 🎉 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR mentioned this pull request Jan 7, 2020
v13.6.0 proposal #31238
Merged
BridgeAR
BridgeAR reviewed Jan 7, 2020
View reviewed changes
Comment thread doc/api/fs.md
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
description: The `fs` options allow overriding the used `fs`
implementation.

@BridgeAR BridgeAR Jan 7, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Late nit: it would be ideal to keep the versioning order the next time.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ronag ronag Jan 7, 2020

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

versioning order?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Jan 7, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The changes entry should be at the top but it's at the bottom of the changes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ronag reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@ronag ronag Jan 7, 2020

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ah, my mistake. I though it was the other way around.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Jan 7, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

There is no clear rule for it so far. So it's different each time and it's just good to keep it consistent in the changes itself. We might want to define an order at some point.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@targos targos mentioned this pull request May 2, 2020
v12.17.0 release proposal #33197
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ChALkeR ChALkeR ChALkeR left review comments
@addaleax addaleax addaleax approved these changes
@BridgeAR BridgeAR BridgeAR left review comments
@mcollina mcollina mcollina approved these changes
@Trott Trott Trott approved these changes
@jasnell jasnell Awaiting requested review from jasnell
+2 more reviewers
@coreyfarrell coreyfarrell coreyfarrell left review comments
@vsemozhetbyt vsemozhetbyt vsemozhetbyt left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

fs Issues and PRs related to file-system APIs and the fs module. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

11 participants

@ronag @jasnell @addaleax @mcollina @coreyfarrell @ChALkeR @nodejs-github-bot @Trott @BridgeAR @vsemozhetbyt @targos
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.