fix: use setEncoding() and read() for crypto.createHash instead of digest() (#11)

This commit is contained in:
Niels Leenheer
2020-11-20 11:05:59 +01:00
committed by GitHub
parent 107823fc2c
commit 477a52e779

View File

@@ -5,11 +5,12 @@ import { d } from './debug';
export const sha = async (filePath: string) => { export const sha = async (filePath: string) => {
d('hashing', filePath); d('hashing', filePath);
const hash = crypto.createHash('sha256'); const hash = crypto.createHash('sha256');
hash.setEncoding('hex');
const fileStream = fs.createReadStream(filePath); const fileStream = fs.createReadStream(filePath);
fileStream.pipe(hash); fileStream.pipe(hash);
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
fileStream.on('end', () => resolve()); fileStream.on('end', () => resolve());
fileStream.on('error', (err) => reject(err)); fileStream.on('error', (err) => reject(err));
}); });
return hash.digest('hex'); return hash.read();
}; };