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

fix(ext-tools): handle end of stream event #352

Merged
merged 1 commit into from
Oct 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions garden-service/src/util/ext-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export class BinaryCmd extends Cmd {
// validate sha256 if provided
const sha256 = hash.read()

// end of stream event
if (sha256 === null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any particular reason to check for null here instead of just a falsey value (e.g. if (sha256) {)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to the docs, stream.read() is explicitly null when the end-of-stream-reached event fires. So I figured it'd be safer to be explicit, a whole host of things can be falsey.

return
}

if (this.spec.sha256 && sha256 !== this.spec.sha256) {
reject(new DownloadError(
`Invalid checksum from ${this.spec.url} (got ${sha256})`,
Expand Down