Skip to content

Conversation

TrySound
Copy link
Contributor

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@TrySound TrySound requested a review from a team as a code owner September 27, 2020 17:18
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 27, 2020
@codecov
Copy link

codecov bot commented Sep 27, 2020

Codecov Report

Merging #1304 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
src/file.ts 99.94% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ce3d89...70f9997. Read the comment docs.

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.
) => {
if (err) {
// Get error message from the body.
rawResponseStream.pipe(
Copy link
Contributor

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 :)

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Sep 28, 2020
@TrySound TrySound changed the title refactor(deps: replace concat-stream with get-stream refactor(deps): replace concat-stream with get-stream Sep 28, 2020
src/file.ts Outdated
fileStream.on('error', callback).pipe(concat(callback.bind(null, null)));
getStream
.buffer(fileStream)
.then(
Copy link
Contributor

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 :)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@stephenplusplus
Copy link
Contributor

@TrySound thank you for noticing this and helping out!

@stephenplusplus stephenplusplus added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 29, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 29, 2020
@stephenplusplus stephenplusplus merged commit afeaa69 into googleapis:master Sep 29, 2020
@stephenplusplus
Copy link
Contributor

Thanks!

@TrySound TrySound deleted the get-stream branch September 29, 2020 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/nodejs-storage API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants