hash.js
function calculateHash(filepath) {
    return new Promise((fulfill, reject) => {
        const file = fs.createReadStream(filepath);
        const hash = crypto.createHash('sha512');
        hash.setEncoding('hex');
        file.on('error', err => {
            reject(err);
        });
        file.on('end', () => {
            hash.end();
            fulfill(hash.read());
        });
        file.pipe(hash);
    });
}
function calculateHash(filepath) {
    return new Promise((fulfill, reject) => {
        const file = fs.createReadStream(filepath);
        const hash = crypto.createHash('sha512');
        hash.setEncoding('hex');
        file.on('error', err => {
            reject(err);
        });
        file.on('end', () => {
            hash.end();
            fulfill(hash.read());
        });
        file.pipe(hash);
    });
}
function calculateHash ( filepath ) { return new Promise ( ( fulfill , reject ) => { const file = fs . createReadStream ( filepath ) ; const hash = crypto . createHash ( 'sha512' ) ; hash . setEncoding ( 'hex' ) ; file . on ( 'error' , err => { reject ( err ) ; } ) ; file . on ( 'end' , ( ) => { hash . end ( ) ; fulfill ( hash . read ( ) ) ; } ) ; file . pipe ( hash ) ; } ) ; }
Calculates hash of the file at the given path.

@param {string} filepath
@returns Promise<string> hex encoded hash
Calculates hash of the file at the given path .