hash-reader.js 801 B

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