-
Notifications
You must be signed in to change notification settings - Fork 389
refactor(deps): replace concat-stream with get-stream #1304
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1304 +/- ##
=======================================
Coverage 98.98% 98.98%
=======================================
Files 14 14
Lines 11580 11581 +1
Branches 529 598 +69
=======================================
+ Hits 11463 11464 +1
Misses 117 117
Continue to review full report at Codecov.
|
Ref https://packagephobia.com/result?p=concat-stream https://packagephobia.com/result?p=get-stream Concat-stream is a big package with not relevant in node 10 dependencies. In this diff I replaced it with dependency-free get-stream with promise based api.
d3c8c7f
to
f3fe66c
Compare
) => { | ||
if (err) { | ||
// Get error message from the body. | ||
rawResponseStream.pipe( |
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.
In the general sense ... are we making this harder than it needs to be?
const results = [];
rawResponseStream
.on('data', results.push)
.on('end', () => {
err.message = results.concat();
throughStream.destroy(err);
});
});
Adding @stephenplusplus, the stream whisperer, to chime in :)
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.
Can this be a problem with utf-8 when ligatures will be in separate chunk from characters?
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.
@TrySound I believe get-stream is doing essentially the example @JustinBeckwith provided, but let me know if I missed it. I think the point is, we could probably duplicate the logic in both of these modules relatively easily and avoid any extra dependencies. In either case, I would still lean towards using get-stream just for simplicity. Especially since it's already a huge win, size-wise, over concat-stream.
src/file.ts
Outdated
fileStream.on('error', callback).pipe(concat(callback.bind(null, null))); | ||
getStream | ||
.buffer(fileStream) | ||
.then( |
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.
This might be easier to read if it was something like:
getStream
.buffer(fileStream)
.then(contents => callback(null, contents))
.catch(callback)
I know you copied our existing callback.bind(null, null)
(thank you for the attention to detail), but I think arrow functions are new since we wrote this, so we can "upgrade" now, if you're willing :)
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.
Not really easier. Refinement will be invalidated and callback will become nullable again.
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.
True, I think TS makes both options much less readable :) I think "bind" was a well-known, useful solution in the old days, but I don't know how many generations of developers are left who will see that and know what's really happening or why. And with arrow functions being an option, I don't think we have a good explanation anymore. Thanks for making the change.
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.
I used optional chaining to simplify this. Looks like everything still works.
@TrySound thank you for noticing this and helping out! |
Thanks! |
Ref https://packagephobia.com/result?p=concat-stream https://packagephobia.com/result?p=get-stream
Concat-stream is a big package with not relevant in node 10 dependencies.
In this diff I replaced it with dependency-free get-stream with promise
based api.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕