get-file-hash.js 527 B

1234567891011121314151617181920212223
  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. const fs = require('fs');
  9. const getStringHash = require('./get-string-hash');
  10. const errors = require('./errors');
  11. module.exports = file => {
  12. try {
  13. const buffer = fs.readFileSync(file);
  14. return getStringHash(buffer);
  15. } catch (err) {
  16. throw new Error(errors['unable-to-get-file-hash'] + ` '${err.message}'`);
  17. }
  18. };