hash.js
function verifyHash(correctHash, filepath) {
    return calculateHash(filepath).then(hash => {
        if (hash !== correctHash) {
            throw new Error(`Incorrect checksum: expected ${correctHash}, got ${hash}`);
        }
        return true;
    });
}
function verifyHash(correctHash, filepath) {
    return calculateHash(filepath).then(hash => {
        if (hash !== correctHash) {
            throw new Error(`Incorrect checksum: expected ${correctHash}, got ${hash}`);
        }
        return true;
    });
}
function verifyHash ( correctHash , filepath ) { return calculateHash ( filepath ) . then ( hash => { if ( hash !== correctHash ) { throw new Error ( ` ${ correctHash } ${ hash } ` ) ; } return true ; } ) ; }
Calculates SHA512 hash of filepath and compares
it to the provided correctHash.

Returns a promise which rejects if the hash is
incorrect, otherwise resolves to true.

@param {string} correctHash expected hex-encoded SHA-512 hash
@param {string} filepath file path
@returns {Promise<boolean>}
Calculates SHA512 hash of filepath and compares it to the provided correctHash .