get-file-hash.js 954 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. var __importDefault = (this && this.__importDefault) || function (mod) {
  9. return (mod && mod.__esModule) ? mod : { "default": mod };
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. exports.getFileHash = void 0;
  13. const fs_extra_1 = __importDefault(require("fs-extra"));
  14. const get_string_hash_1 = require("./get-string-hash");
  15. const errors_1 = require("./errors");
  16. function getFileHash(file) {
  17. try {
  18. const buffer = fs_extra_1.default.readFileSync(file);
  19. return (0, get_string_hash_1.getStringHash)(buffer);
  20. }
  21. catch (err) {
  22. throw new Error(errors_1.errors['unable-to-get-file-hash'] +
  23. ` '${err instanceof Error && err.message ? err.message : ''}'`);
  24. }
  25. }
  26. exports.getFileHash = getFileHash;