Skip to content

Conversation

@ryanpbrewster
Copy link
Contributor

There are still customer reports of corrupted downloads that finish successfully. This is a fairly blunt way of double-checking that the download is valid.

Copy link
Contributor

@bkendall bkendall left a comment

Choose a reason for hiding this comment

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

Looks like you need to run npm run format and you'll be good to go for the tests.

Why use the size rather than a hash? I can see either working okay, but hash would be slightly better in my opinion

@bkendall bkendall assigned ryanpbrewster and unassigned bkendall Feb 13, 2019
@ryanpbrewster
Copy link
Contributor Author

  • computing a hash requires pulling in a new dependency (the crypto package)
  • almost every developer will understand file size, so the error message may help more
  • I am very lazy

let tmpFile = tmp.fileSync();
let req = request.get(emulator.remoteUrl);
let writeStream = fs.createWriteStream(tmpFile.name);
let bytesDownloaded = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't look like this is used

@bkendall
Copy link
Contributor

  • computing a hash requires pulling in a new dependency (the crypto package)

crypto is a built-in library of node, so it's not actually much heavy lifting. that said, that's fine. If you start getting errors where it's corrupted but the right size, you may want to consider using a hash...

@ryanpbrewster
Copy link
Contributor Author

Went ahead and added a checksum as well. Code is now a bit messy, would appreciate pointers here.

Copy link
Contributor

@bkendall bkendall left a comment

Choose a reason for hiding this comment

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

looks good - I suggested a bit of refactoring around your else statements that should make it a bit nicer, but looks good from here!

{ exit: 1 }
)
);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

this else block can be removed if the reject above is returned

Copy link
Contributor

Choose a reason for hiding this comment

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

(and the same is true of the else block that this entire check is 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.

converted these to ternary statements, lmk if that's non-idiomatic

const hash = crypto.createHash('md5'),
const stream = fs.createReadStream(tmpFile.name);
stream.on('data', data => hash.update(data));
stream.on('end', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be an arrow function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

stream.on('data', data => hash.update(data));
stream.on('end', function() {
const checksum = hash.digest('hex');
if (checksum != emulator.expectedHash) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (checksum != emulator.expectedHash) {
if (checksum !== emulator.expectedHash) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#javascript

@bkendall
Copy link
Contributor

LGTM. fix up the CI and you're good to go.

@ryanpbrewster ryanpbrewster merged commit 757db03 into master Feb 13, 2019
@ryanpbrewster ryanpbrewster deleted the rpb/validate-emulator-download branch February 13, 2019 21:37
@coveralls
Copy link

coveralls commented Feb 13, 2019

Coverage Status

Coverage remained the same at 60.427% when pulling 39bf9c5 on rpb/validate-emulator-download into 561b593 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Manual indication that this has passed CLA.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants