calcfilehash.js 532 B

1234567891011121314151617181920
  1. var type = self.data.type,
  2. bin = self.data.bin,
  3. hashOpts = self.data.hashOpts;
  4. self.res = {};
  5. if (type === 'md5') {
  6. let sp = new self.SparkMD5.ArrayBuffer();
  7. sp.append(bin);
  8. self.res.hash = sp.end();
  9. } else {
  10. let sha = new jsSHA('SHA' + (type.length === 5? type : ('-' + type)).toUpperCase(), 'ARRAYBUFFER'),
  11. opts = {};
  12. if (type === 'ke128') {
  13. opts.shakeLen = hashOpts.shake128len;
  14. } else if (type === 'ke256') {
  15. opts.shakeLen = hashOpts.shake256len;
  16. }
  17. sha.update(bin);
  18. self.res.hash = sha.getHash('HEX', opts);
  19. }