mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 10:46:31 +00:00
fix(perf): Remove support for CRC32 checksumming
As crc32-stream was identified as a massive performance bottleneck, we remove it, and default to Node's crypto API with md5 instead. Change-Type: minor
This commit is contained in:
parent
68b33fcfb9
commit
35772b0370
@ -90,8 +90,8 @@ permissions.isElevated().then((elevated) => {
|
|||||||
return Bluebird.try(() => {
|
return Bluebird.try(() => {
|
||||||
console.log(messages.info.flashComplete(path.basename(results.imagePath), results.flash.drive))
|
console.log(messages.info.flashComplete(path.basename(results.imagePath), results.flash.drive))
|
||||||
|
|
||||||
if (results.flash.checksum.crc32) {
|
if (results.flash.checksum.md5) {
|
||||||
console.log(`Checksum: ${results.flash.checksum.crc32}`)
|
console.log(`Checksum: ${results.flash.checksum.md5}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Bluebird.resolve()
|
return Bluebird.resolve()
|
||||||
|
@ -49,7 +49,7 @@ exports.writeImage = (imagePath, drive, options, onProgress) => {
|
|||||||
path: drive,
|
path: drive,
|
||||||
imagePath,
|
imagePath,
|
||||||
verify: options.validateWriteOnSuccess,
|
verify: options.validateWriteOnSuccess,
|
||||||
checksumAlgorithms: [ 'crc32' ],
|
checksumAlgorithms: [ 'md5' ],
|
||||||
unmountOnSuccess: options.unmountOnSuccess
|
unmountOnSuccess: options.unmountOnSuccess
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -18,26 +18,8 @@
|
|||||||
|
|
||||||
const stream = require('readable-stream')
|
const stream = require('readable-stream')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const CRC32Stream = require('crc32-stream')
|
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
/**
|
|
||||||
* @summary Get a hash stream
|
|
||||||
* @function
|
|
||||||
* @private
|
|
||||||
* @example
|
|
||||||
* var md5Stream = getHashStream('md5')
|
|
||||||
*
|
|
||||||
* @param {String} algorithm - either `crc32` or anything supported by `crypto.Hash`
|
|
||||||
* @returns {Stream.Transform}
|
|
||||||
*/
|
|
||||||
const getHashStream = (algorithm) => {
|
|
||||||
if (algorithm === 'crc32') {
|
|
||||||
return new CRC32Stream()
|
|
||||||
}
|
|
||||||
return crypto.createHash(algorithm)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Create an instance of ChecksumStream
|
* @summary Create an instance of ChecksumStream
|
||||||
* @name ChecksumStream
|
* @name ChecksumStream
|
||||||
@ -52,13 +34,12 @@ class ChecksumStream extends stream.Transform {
|
|||||||
* @param {String[]} options.algorithms - hash algorithms
|
* @param {String[]} options.algorithms - hash algorithms
|
||||||
* @example
|
* @example
|
||||||
* var checksum = new ChecksumStream({
|
* var checksum = new ChecksumStream({
|
||||||
* algorithms: [ 'crc32', 'md5' ]
|
* algorithms: [ 'md5' ]
|
||||||
* })
|
* })
|
||||||
*
|
*
|
||||||
* checksum.once('checksum', (checksum) => {
|
* checksum.once('checksum', (checksum) => {
|
||||||
* // checksum: {
|
* // checksum: {
|
||||||
* // crc32: 'EF28AF1C',
|
* // md5: '55a4eb779e08f604c41ba1cbfff47ada'
|
||||||
* // md5: ''
|
|
||||||
* // }
|
* // }
|
||||||
* })
|
* })
|
||||||
*
|
*
|
||||||
@ -85,7 +66,7 @@ class ChecksumStream extends stream.Transform {
|
|||||||
* const hash = this._createHash(algorithm)
|
* const hash = this._createHash(algorithm)
|
||||||
*/
|
*/
|
||||||
_createHash (algorithm) {
|
_createHash (algorithm) {
|
||||||
const hash = _.attempt(getHashStream, algorithm)
|
const hash = _.attempt(crypto.createHash, algorithm)
|
||||||
|
|
||||||
if (_.isError(hash)) {
|
if (_.isError(hash)) {
|
||||||
hash.message += ` "${algorithm}"`
|
hash.message += ` "${algorithm}"`
|
||||||
@ -108,18 +89,10 @@ class ChecksumStream extends stream.Transform {
|
|||||||
return this.emit('error', error)
|
return this.emit('error', error)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (algorithm === 'crc32') {
|
|
||||||
hash.once('end', () => {
|
|
||||||
this.results[algorithm] = hash.digest('hex')
|
|
||||||
check()
|
|
||||||
})
|
|
||||||
hash.resume()
|
|
||||||
} else {
|
|
||||||
hash.once('readable', () => {
|
hash.once('readable', () => {
|
||||||
this.results[algorithm] = hash.read().toString('hex')
|
this.results[algorithm] = hash.read().toString('hex')
|
||||||
check()
|
check()
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user