hash-reader.js 679 B

123456789101112131415161718192021222324
  1. import { BaseHashReader } from '../base/hash-reader.js';
  2. import { defaultHashLength } from '../base/hash-fn.js';
  3. /**
  4. * A hash reader for WebAssembly targets.
  5. */
  6. export class NodeHashReader extends BaseHashReader {
  7. /**
  8. * Converts first 32 bytes of the hash to a string with the given encoding.
  9. */
  10. toString(encoding = 'hex') {
  11. return this.toBuffer().toString(encoding);
  12. }
  13. /**
  14. * Converts first 32 bytes of the hash to an array.
  15. */
  16. toBuffer() {
  17. this.position = BigInt(0);
  18. return this.read(defaultHashLength);
  19. }
  20. alloc(bytes) {
  21. return Buffer.alloc(bytes);
  22. }
  23. }
  24. //# sourceMappingURL=hash-reader.js.map