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

Proposal: Stream support #44

Closed
wants to merge 1 commit into from

Conversation

mikermcneil
Copy link
Contributor

Proposed change

Add support for passing in writable streams to .outputFile and similar methods, e.g. usage:

require('fs-extra').outputFile('./foo.md', fs.createReadStream('./README.md'))

The PR implements a rough pass at this to outputFile(), just to capture the idea (no new tests, etc)

How it works currently

Currently, if you were to do:

require('fs-extra').outputFile('./foo.md', fs.createReadStream('./README.md'))

you get a file:

[object Object]

What does everyone think? @jprichardson would you be ok w/ something like this? I'm happy to send PRs, add tests, etc.

To try it

$ npm install fs-extra@git://github.com/mikermcneil/node-fs-extra.git#patch-1

Stuff that probably needs to be added

  • Obviously tests
  • Check that the stream is an instanceof Writable not just Stream
  • Might even want to check that the writable stream hasn't been opened yet (not sure how to do this off-hand but I don't think it would be hard to do)

Currently, if you were to do:

```javascript
require('fs-extra').outputFile('./foo.md', fs.createReadStream('./README.md'))
```

you get a file:
```md
[object Object]
```

What does everyone think?  @jprichardson would you be ok w/ something like this? I'm happy to send PRs, add tests, etc.
@mikermcneil
Copy link
Contributor Author

@jprichardson and an aside- thanks so much for putting this together. It's one of my favorite modules and our team is using fs-extra in most of our projects, esp. sails and most recently sails-generate.

@jprichardson
Copy link
Owner

Thanks for the kind words! I'm in favor of it, although it does feel kinda weird, but I understand the point of wanting the destination directory path to exist before the file is written and having the convenience of passing the stream saves lines of code. Ya, I'm in favor. Add some tests and I'll include it! Thanks.

@jprichardson
Copy link
Owner

Closing this. As far as I can tell, this has been completed by #118 and https://github.com/jprichardson/node-fs-extra/releases/tag/0.17.0. If I missed something, please reopen or create a new issue. Thanks :)

ovr pushed a commit to ovr/node-fs-extra that referenced this pull request Nov 12, 2020
ovr pushed a commit to ovr/node-fs-extra that referenced this pull request Nov 12, 2020
## [1.3.3](oclif/errors@v1.3.2...v1.3.3) (2020-06-29)

### Bug Fixes

* remove deprecation warning for render in exit error ([jprichardson#44](oclif/errors#44)) ([3b2e5fa](oclif/errors@3b2e5fa))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants