hash-reader.js 708 B

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