hash-reader.d.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { IDisposable } from './disposable';
  2. /**
  3. * The maximum number of bytes that can be read from the hash.
  4. *
  5. * Calculated out 2^64-1, since `Xn` syntax (for `Xn ** Yn`) requires TS
  6. * targeting esnext/es2020 which includes features that Node 10 doesn't
  7. * yet supported.
  8. */
  9. export declare const maxHashBytes: bigint;
  10. /**
  11. * The HashReader is a type returned from any of the hash functions. It can
  12. */
  13. export interface IHashReader<T> extends IDisposable {
  14. /**
  15. * Returns the position of the reader in the hash. Can be written to to seek.
  16. */
  17. position: bigint;
  18. /**
  19. * Reads data from the hash into the target array. The target will always
  20. * be completely filled with data.
  21. */
  22. readInto(target: Uint8Array): void;
  23. /**
  24. * Reads and returns the given number of bytes from the hash, advancing
  25. * the position of the reader.
  26. */
  27. read(bytes: number): T;
  28. }
  29. /**
  30. * Underlying native or wasm module code backing the reader.
  31. * @hidden
  32. */
  33. export interface IInternalReader {
  34. free?(): void;
  35. fill(target: Uint8Array): void;
  36. set_position(position: bigint): void;
  37. }
  38. /**
  39. * Base hash reader implementation.
  40. */
  41. export declare abstract class BaseHashReader<T extends Uint8Array> implements IHashReader<T> {
  42. private reader;
  43. private pos;
  44. get position(): bigint;
  45. set position(value: bigint);
  46. constructor(reader: IInternalReader);
  47. /**
  48. * @inheritdoc
  49. */
  50. readInto(target: Uint8Array): void;
  51. /**
  52. * @inheritdoc
  53. */
  54. read(bytes: number): T;
  55. /**
  56. * @inheritdoc
  57. */
  58. dispose(): void;
  59. protected abstract alloc(bytes: number): T;
  60. private boundsCheck;
  61. }