Merge pull request #2292 from resin-io/bench-verify

feat(writer): Use xxHash instead of SHA512 for verification
This commit is contained in:
Jonas Hermsmeier 2018-05-09 16:46:02 +02:00 committed by GitHub
commit 28cb21db13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 5 deletions

View File

@ -99,7 +99,7 @@ permissions.isElevated().then((elevated) => {
const writer = new ImageWriter({
verify: options.check,
unmountOnSuccess: options.unmount,
checksumAlgorithms: options.check ? [ 'sha512' ] : []
checksumAlgorithms: options.check ? [ 'xxhash' ] : []
})
/**
@ -133,7 +133,7 @@ permissions.isElevated().then((elevated) => {
exitCode = EXIT_CODES.GENERAL_ERROR
console.log(` - ${result.device.device}: ${result.error.message}`)
} else {
console.log(` - ${result.device.device}: ${result.checksum.sha512}`)
console.log(` - ${result.device.device}: ${result.checksum.xxhash}`)
}
})
}

View File

@ -192,7 +192,7 @@ exports.performWrite = (image, drives, onProgress) => {
destinations: drives,
validateWriteOnSuccess: settings.get('validateWriteOnSuccess'),
unmountOnSuccess: settings.get('unmountOnSuccess'),
checksumAlgorithms: [ 'sha512' ]
checksumAlgorithms: [ 'xxhash' ]
})
})

View File

@ -18,6 +18,7 @@
const stream = require('readable-stream')
const crypto = require('crypto')
const xxhash = require('xxhash')
const _ = require('lodash')
/**
@ -66,7 +67,16 @@ class ChecksumStream extends stream.Transform {
* const hash = this._createHash(algorithm)
*/
_createHash (algorithm) {
const hash = _.attempt(crypto.createHash, algorithm)
let hash = null
if (algorithm === 'xxhash') {
// Seed value 0x45544348 = ASCII "ETCH"
const seed = 0x45544348
const is64Bit = process.arch === 'x64' || process.arch === 'aarch64'
hash = new xxhash.Stream(seed, is64Bit ? 64 : 32)
} else {
hash = _.attempt(crypto.createHash, algorithm)
}
if (_.isError(hash)) {
hash.message += ` "${algorithm}"`

View File

@ -810,7 +810,8 @@ class ImageWriter extends EventEmitter {
fd: destination.fd,
autoClose: false,
start: 0,
end: size
end: size,
highWaterMark: 1048576
})
pipeline.bind(source, 'error')

4
npm-shrinkwrap.json generated
View File

@ -9093,6 +9093,10 @@
"resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz",
"dev": true
},
"xxhash": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/xxhash/-/xxhash-0.2.4.tgz"
},
"y18n": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz"

View File

@ -91,6 +91,7 @@
"uuid": "3.0.1",
"winusb-driver-generator": "1.1.7",
"xml2js": "0.4.17",
"xxhash": "0.2.4",
"yargs": "11.0.0",
"yauzl": "2.6.0"
},