mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 11:16:39 +00:00
Merge pull request #2292 from resin-io/bench-verify
feat(writer): Use xxHash instead of SHA512 for verification
This commit is contained in:
commit
28cb21db13
@ -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}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ exports.performWrite = (image, drives, onProgress) => {
|
||||
destinations: drives,
|
||||
validateWriteOnSuccess: settings.get('validateWriteOnSuccess'),
|
||||
unmountOnSuccess: settings.get('unmountOnSuccess'),
|
||||
checksumAlgorithms: [ 'sha512' ]
|
||||
checksumAlgorithms: [ 'xxhash' ]
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -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}"`
|
||||
|
@ -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
4
npm-shrinkwrap.json
generated
@ -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"
|
||||
|
@ -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"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user