hash-reader.js 839 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const hash_reader_1 = require("../base/hash-reader");
  4. const hash_1 = require("./hash");
  5. const index_1 = require("../base/index");
  6. /**
  7. * A hash reader for WebAssembly targets.
  8. */
  9. class BrowserHashReader extends hash_reader_1.BaseHashReader {
  10. /**
  11. * Converts first 32 bytes of the hash to a string with the given encoding.
  12. */
  13. toString(encoding = 'hex') {
  14. return this.toArray().toString(encoding);
  15. }
  16. /**
  17. * Converts first 32 bytes of the hash to an array.
  18. */
  19. toArray() {
  20. this.position = BigInt(0);
  21. return this.read(index_1.defaultHashLength);
  22. }
  23. alloc(bytes) {
  24. return new hash_1.Hash(bytes);
  25. }
  26. }
  27. exports.BrowserHashReader = BrowserHashReader;
  28. //# sourceMappingURL=hash-reader.js.map