mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-15 15:26:31 +00:00
fix(writer): Don't calculate checksum before block-stream (#1858)
The checksum-stream being situated in front of the block-stream, which ensures block size alignment to multiples of 512, and pads the last block, caused the checksum to be incorrectly calculated for images where the last block needed to be padded. Change-Type: patch
This commit is contained in:
parent
0e02998faf
commit
b3b52fce62
@ -121,7 +121,7 @@ class ChecksumStream extends stream.Transform {
|
||||
})
|
||||
}
|
||||
|
||||
return this.pipe(hash)
|
||||
return hash
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,8 +134,24 @@ class ChecksumStream extends stream.Transform {
|
||||
* checksumStream.write(buffer)
|
||||
*/
|
||||
_transform (chunk, encoding, next) {
|
||||
this.push(chunk)
|
||||
next()
|
||||
for (let index = 0; index < this.hashes.length; index += 1) {
|
||||
this.hashes[index].write(chunk)
|
||||
}
|
||||
next(null, chunk)
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary End the hash streams once this stream ends
|
||||
* @private
|
||||
* @param {Function} done - callback
|
||||
* @example
|
||||
* checksumStream.end()
|
||||
*/
|
||||
_flush (done) {
|
||||
for (let index = 0; index < this.hashes.length; index += 1) {
|
||||
this.hashes[index].end()
|
||||
}
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,11 +206,12 @@ class ImageWriter extends EventEmitter {
|
||||
} else {
|
||||
debug('write:blockstream')
|
||||
const checksumStream = new ChecksumStream({
|
||||
objectMode: true,
|
||||
algorithms: options.checksumAlgorithms
|
||||
})
|
||||
pipeline.append(new BlockStream())
|
||||
pipeline.append(checksumStream)
|
||||
pipeline.bind(checksumStream, 'checksum')
|
||||
pipeline.append(new BlockStream())
|
||||
}
|
||||
|
||||
const target = new BlockWriteStream({
|
||||
|
Loading…
x
Reference in New Issue
Block a user