mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-21 10:16:32 +00:00
Merge pull request #2108 from resin-io/switch-chksm-algo
fix(perf): Remove support for CRC32 checksumming Close #643
This commit is contained in:
commit
f72cc6bbbc
@ -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
|
||||||
}
|
}
|
||||||
|
8
npm-shrinkwrap.json
generated
8
npm-shrinkwrap.json
generated
@ -1706,12 +1706,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz"
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz"
|
||||||
},
|
},
|
||||||
"crc": {
|
"crc": {
|
||||||
"version": "3.4.4",
|
"version": "3.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz"
|
"resolved": "https://registry.npmjs.org/crc/-/crc-3.5.0.tgz",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"crc32-stream": {
|
"crc32-stream": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-2.0.0.tgz"
|
"resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-2.0.0.tgz",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"create-ecdh": {
|
"create-ecdh": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
"bootstrap-sass": "3.3.6",
|
"bootstrap-sass": "3.3.6",
|
||||||
"chalk": "1.1.3",
|
"chalk": "1.1.3",
|
||||||
"command-join": "2.0.0",
|
"command-join": "2.0.0",
|
||||||
"crc32-stream": "2.0.0",
|
|
||||||
"debug": "3.1.0",
|
"debug": "3.1.0",
|
||||||
"drivelist": "6.0.4",
|
"drivelist": "6.0.4",
|
||||||
"electron-is-running-in-asar": "1.0.0",
|
"electron-is-running-in-asar": "1.0.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user