mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
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
1 changed files with 11 additions and 4 deletions
|
@ -68,10 +68,17 @@ class Package {
|
|||
|
||||
logger.debug('Validating checksums');
|
||||
logger.debug(`Assert sha256(pkg.tar.gz) == ${this.checksum}`);
|
||||
const cs = crypto
|
||||
.create_hash('sha256')
|
||||
.update(fss.readFileSync(pkgpath))
|
||||
.digest('hex');
|
||||
const hash = crypto.create_hash('sha256');
|
||||
|
||||
const read_stream = fss.create_read_stream(pkgpath);
|
||||
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) {
|
||||
throw new Error(`Checksum miss-match want: ${val} got: ${cs}`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue