-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtype.ts
84 lines (72 loc) · 2.13 KB
/
type.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import type {
MultihashDigest,
MultihashHasher,
SyncMultihashHasher,
} from "multiformats"
export interface Digest<Code extends number, Size extends number>
extends MultihashDigest<Code> {
size: Size
}
export interface Hasher<Code extends number, Size extends number>
extends MultihashHasher<Code> {
size: Size
/**
* Computes the digest of the given input and writes it into the given output
* at the given offset. Unless `asMultihash` is `false` multihash is
* written otherwise only the digest (without multihash prefix) is written.
*/
digestInto(
input: Uint8Array,
output: Uint8Array,
offset?: number,
asMultihash?: boolean
): void | Promise<void>
}
export interface SyncHasher<Code extends number, Size extends number>
extends SyncMultihashHasher<Code> {
size: Size
digest(input: Uint8Array): Digest<Code, Size>
/**
* Computes the digest of the given input and writes it into the given output
* at the given offset. Unless `asMultihash` is `false` multihash is
* written otherwise only the digest (without multihash prefix) is written.
*/
digestInto(
input: Uint8Array,
output: Uint8Array,
offset?: number,
asMultihash?: boolean
): void
}
export interface StreamingHasher<Code extends number, Size extends number> {
size: Size
code: Code
name: string
/**
* Number of bytes currently consumed.
*/
count(): bigint
/**
* Returns multihash digest of the bytes written so far.
*/
digest(): Digest<Code, Size>
/**
* Computes the digest of the given input and writes it into the given output
* at the given offset. Unless `asMultihash` is `false` multihash is
* written otherwise only the digest (without multihash prefix) is written.
*/
digestInto(output: Uint8Array, offset?: number, asMultihash?: boolean): this
/**
* Writes bytes to be digested.
*/
write(bytes: Uint8Array): this
/**
* Resets this hasher to its initial state.
*/
reset(): this
/**
* Disposes this hasher and frees up any resources it may be holding on to.
* After this is called this hasher should not be used.
*/
dispose(): void
}