compute hash in chunks.
Previously we were loading the entire package file into memory, then updating the hash. Now we update the hash with chunks of the data as it is read in. Should fix #259
This commit is contained in:
parent
79c7f471a1
commit
c71aea6166
|
@ -68,10 +68,17 @@ class Package {
|
||||||
|
|
||||||
logger.debug('Validating checksums');
|
logger.debug('Validating checksums');
|
||||||
logger.debug(`Assert sha256(pkg.tar.gz) == ${this.checksum}`);
|
logger.debug(`Assert sha256(pkg.tar.gz) == ${this.checksum}`);
|
||||||
const cs = crypto
|
const hash = crypto.create_hash('sha256');
|
||||||
.create_hash('sha256')
|
|
||||||
.update(fss.readFileSync(pkgpath))
|
const read_stream = fss.create_read_stream(pkgpath);
|
||||||
.digest('hex');
|
await new Promise((resolve, reject) => {
|
||||||
|
read_stream.on('data', chunk => hash.update(chunk));
|
||||||
|
read_stream.on('end', () => resolve());
|
||||||
|
read_stream.on('error', error => reject(error))
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const cs = hash.digest('hex');
|
||||||
|
|
||||||
if (cs !== this.checksum) {
|
if (cs !== this.checksum) {
|
||||||
throw new Error(`Checksum miss-match want: ${val} got: ${cs}`);
|
throw new Error(`Checksum miss-match want: ${val} got: ${cs}`);
|
||||||
|
|
Loading…
Reference in New Issue