UNPKG

784 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.hashFile = void 0;
4const crypto_1 = require("crypto");
5const fs_1 = require("fs");
6function hashFile(file, algorithm = "sha512", encoding = "base64", options) {
7 return new Promise((resolve, reject) => {
8 const hash = (0, crypto_1.createHash)(algorithm);
9 hash.on("error", reject).setEncoding(encoding);
10 (0, fs_1.createReadStream)(file, { ...options, highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */ })
11 .on("error", reject)
12 .on("end", () => {
13 hash.end();
14 resolve(hash.read());
15 })
16 .pipe(hash, { end: false });
17 });
18}
19exports.hashFile = hashFile;
20//# sourceMappingURL=hash.js.map
\No newline at end of file