@rasmx/hash 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +68 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -65,7 +65,6 @@ export const hash = {
|
|
|
65
65
|
md5: (d) => { check(); return wasm.md5_hex(toBuf(d)); },
|
|
66
66
|
|
|
67
67
|
stream: async (readable, hasher) => {
|
|
68
|
-
check();
|
|
69
68
|
const reader = readable.getReader();
|
|
70
69
|
try {
|
|
71
70
|
while (true) {
|
|
@@ -85,58 +84,111 @@ class BaseIncremental {
|
|
|
85
84
|
check();
|
|
86
85
|
this.i = wasmClassInstance;
|
|
87
86
|
}
|
|
88
|
-
update(d) {
|
|
89
|
-
|
|
87
|
+
update(d) {
|
|
88
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
89
|
+
this.i.update(toBuf(d));
|
|
90
|
+
}
|
|
91
|
+
free() {
|
|
90
92
|
if (this.i) {
|
|
91
|
-
this.i.free();
|
|
92
|
-
this.i = null;
|
|
93
|
-
}
|
|
93
|
+
this.i.free();
|
|
94
|
+
this.i = null;
|
|
95
|
+
}
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
export class IncrementalSha256 extends BaseIncremental {
|
|
98
100
|
constructor() { super(new wasm.IncrementalSha256()); }
|
|
99
|
-
finalize() {
|
|
101
|
+
finalize() {
|
|
102
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
103
|
+
const res = this.i.finalize();
|
|
104
|
+
this.i = null;
|
|
105
|
+
return res;
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
108
|
|
|
102
109
|
export class IncrementalSha512 extends BaseIncremental {
|
|
103
110
|
constructor() { super(new wasm.IncrementalSha512()); }
|
|
104
|
-
finalize() {
|
|
111
|
+
finalize() {
|
|
112
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
113
|
+
const res = this.i.finalize();
|
|
114
|
+
this.i = null;
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
105
117
|
}
|
|
106
118
|
|
|
107
119
|
export class IncrementalSha3_256 extends BaseIncremental {
|
|
108
120
|
constructor() { super(new wasm.IncrementalSha3_256()); }
|
|
109
|
-
finalize() {
|
|
121
|
+
finalize() {
|
|
122
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
123
|
+
const res = this.i.finalize();
|
|
124
|
+
this.i = null;
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
110
127
|
}
|
|
111
128
|
|
|
112
129
|
export class IncrementalKeccak256 extends BaseIncremental {
|
|
113
130
|
constructor() { super(new wasm.IncrementalKeccak256()); }
|
|
114
|
-
finalize() {
|
|
131
|
+
finalize() {
|
|
132
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
133
|
+
const res = this.i.finalize();
|
|
134
|
+
this.i = null;
|
|
135
|
+
return res;
|
|
136
|
+
}
|
|
115
137
|
}
|
|
116
138
|
|
|
117
139
|
export class IncrementalMd5 extends BaseIncremental {
|
|
118
140
|
constructor() { super(new wasm.IncrementalMd5()); }
|
|
119
|
-
finalize() {
|
|
141
|
+
finalize() {
|
|
142
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
143
|
+
const res = this.i.finalize();
|
|
144
|
+
this.i = null;
|
|
145
|
+
return res;
|
|
146
|
+
}
|
|
120
147
|
}
|
|
121
148
|
|
|
122
149
|
export class IncrementalBlake3 extends BaseIncremental {
|
|
123
150
|
constructor() { super(new wasm.IncrementalBlake3()); }
|
|
124
|
-
finalize() {
|
|
151
|
+
finalize() {
|
|
152
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
153
|
+
const res = this.i.finalize();
|
|
154
|
+
this.i = null;
|
|
155
|
+
return res;
|
|
156
|
+
}
|
|
125
157
|
}
|
|
126
158
|
|
|
127
159
|
export class IncrementalXxh3 extends BaseIncremental {
|
|
128
160
|
constructor() { super(new wasm.IncrementalXxh3()); }
|
|
129
|
-
finalize64() {
|
|
130
|
-
|
|
161
|
+
finalize64() {
|
|
162
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
163
|
+
const res = this.i.finalize_64();
|
|
164
|
+
this.i = null;
|
|
165
|
+
return res;
|
|
166
|
+
}
|
|
167
|
+
finalize128() {
|
|
168
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
169
|
+
const res = this.i.finalize_128();
|
|
170
|
+
this.i = null;
|
|
171
|
+
return res;
|
|
172
|
+
}
|
|
131
173
|
finalize() { return this.finalize64(); }
|
|
132
174
|
}
|
|
133
175
|
|
|
134
176
|
export class IncrementalXxh32 extends BaseIncremental {
|
|
135
177
|
constructor(seed = 0) { super(new wasm.IncrementalXxh32(seed)); }
|
|
136
|
-
finalize() {
|
|
178
|
+
finalize() {
|
|
179
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
180
|
+
const res = this.i.finalize();
|
|
181
|
+
this.i = null;
|
|
182
|
+
return res;
|
|
183
|
+
}
|
|
137
184
|
}
|
|
138
185
|
|
|
139
186
|
export class IncrementalXxh64 extends BaseIncremental {
|
|
140
187
|
constructor(seed = 0n) { super(new wasm.IncrementalXxh64(BigInt(seed))); }
|
|
141
|
-
finalize() {
|
|
188
|
+
finalize() {
|
|
189
|
+
if (!this.i) throw new Error("Hasher already finalized or freed");
|
|
190
|
+
const res = this.i.finalize();
|
|
191
|
+
this.i = null;
|
|
192
|
+
return res;
|
|
193
|
+
}
|
|
142
194
|
}
|
package/package.json
CHANGED