hash.js 784 B

1234567891011121314151617181920
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.hashFile = void 0;
  4. const crypto_1 = require("crypto");
  5. const fs_1 = require("fs");
  6. function 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. }
  19. exports.hashFile = hashFile;
  20. //# sourceMappingURL=hash.js.map