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:
Jonas Hermsmeier 2017-11-17 21:37:49 +01:00 committed by GitHub
parent 0e02998faf
commit b3b52fce62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -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()
}
}

View File

@ -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({