pure-md5 0.2.0 → 0.2.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.
Files changed (177) hide show
  1. package/README.md +38 -24
  2. package/dist/adapters/ie11.cjs +1 -2
  3. package/dist/adapters/ie11.js +1 -2
  4. package/dist/adapters/node.cjs +1 -2
  5. package/dist/adapters/node.js +1 -2
  6. package/dist/adapters/webcrypto.cjs +1 -2
  7. package/dist/adapters/webcrypto.js +1 -2
  8. package/dist/index.cjs +1 -2
  9. package/dist/index.d.ts +149 -5
  10. package/dist/index.js +3 -2
  11. package/dist/md5.cjs +1 -0
  12. package/dist/md5.d.ts +20 -0
  13. package/dist/md5.js +1 -0
  14. package/dist/stream/md5-stream.cjs +1 -2
  15. package/dist/stream/md5-stream.js +1 -2
  16. package/dist/stream/whatwg-stream.cjs +1 -2
  17. package/dist/stream/whatwg-stream.js +1 -2
  18. package/dist/utils/detect.cjs +1 -2
  19. package/dist/utils/detect.js +3 -2
  20. package/package.json +10 -15
  21. package/pure-md5-0.2.1.tgz +0 -0
  22. package/test-tree-shake.mjs +12 -0
  23. package/.aliases +0 -19
  24. package/.bash_profile +0 -12
  25. package/.bash_prompt +0 -56
  26. package/.changeset/README.md +0 -32
  27. package/.changeset/config.json +0 -16
  28. package/.continue/mcpServers/new-mcp-server.yaml +0 -10
  29. package/.continue/rules +0 -29
  30. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
  31. package/.github/ISSUE_TEMPLATE/documentation.md +0 -20
  32. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  33. package/.github/PULL_REQUEST_TEMPLATE.md +0 -35
  34. package/.github/workflows/npm-publish.yml +0 -33
  35. package/.github/workflows/release.yml +0 -42
  36. package/CHANGELOG.md +0 -9
  37. package/CONTRIBUTING.md +0 -203
  38. package/MIGRATION_GUIDE_STREAMS.md +0 -374
  39. package/STREAM_API.md +0 -582
  40. package/STREAM_BENCHMARKS.md +0 -232
  41. package/STREAM_EXAMPLES.md +0 -669
  42. package/STREAM_OPTIMIZATION_REPORT.md +0 -136
  43. package/STREAM_TROUBLESHOOTING.md +0 -537
  44. package/WEB_CRYPTO_TESTS_SUMMARY.md +0 -140
  45. package/WHATWG_STREAMS.md +0 -191
  46. package/__tests__/adapters/node-crypto.test.ts +0 -167
  47. package/__tests__/adapters/web-crypto-node.test.ts +0 -73
  48. package/__tests__/adapters/web-crypto.test.ts +0 -195
  49. package/__tests__/add32.test.ts +0 -33
  50. package/__tests__/fallback.test.ts +0 -345
  51. package/__tests__/hex.test.ts +0 -38
  52. package/__tests__/hex_chr.test.ts +0 -20
  53. package/__tests__/index.test.ts +0 -87
  54. package/__tests__/integration/fixtures/test-file.txt +0 -1
  55. package/__tests__/integration/md5-stream-file.test.ts +0 -293
  56. package/__tests__/integration/node-crypto-file.test.ts +0 -86
  57. package/__tests__/integration/web-crypto.test.ts +0 -38
  58. package/__tests__/md51.test.ts +0 -73
  59. package/__tests__/md5block.test.ts +0 -61
  60. package/__tests__/md5cycle.test.ts +0 -48
  61. package/__tests__/round-functions.test.ts +0 -87
  62. package/__tests__/stream/fs-utils.test.ts +0 -209
  63. package/__tests__/stream/md5-stream-edge-cases.test.ts +0 -461
  64. package/__tests__/stream/md5-stream.test.ts +0 -418
  65. package/__tests__/stream/whatwg-stream.test.ts +0 -355
  66. package/__tests__/stream/whatwg-stream.test.ts.bak2 +0 -335
  67. package/benchmarks/md5-stream.bench.ts +0 -212
  68. package/benchmarks/whatwg-stream.bench.ts +0 -180
  69. package/dist/adapters/ie11.cjs.map +0 -1
  70. package/dist/adapters/ie11.js.map +0 -1
  71. package/dist/adapters/node.cjs.map +0 -1
  72. package/dist/adapters/node.js.map +0 -1
  73. package/dist/adapters/webcrypto.cjs.map +0 -1
  74. package/dist/adapters/webcrypto.js.map +0 -1
  75. package/dist/chunk-2YXXFGBV.js +0 -2
  76. package/dist/chunk-2YXXFGBV.js.map +0 -1
  77. package/dist/chunk-4KSCMS4Q.js +0 -2
  78. package/dist/chunk-4KSCMS4Q.js.map +0 -1
  79. package/dist/chunk-6P2QV5SR.js +0 -4
  80. package/dist/chunk-6P2QV5SR.js.map +0 -1
  81. package/dist/chunk-G5WHEAIQ.js +0 -2
  82. package/dist/chunk-G5WHEAIQ.js.map +0 -1
  83. package/dist/chunk-H2K353LR.js +0 -2
  84. package/dist/chunk-H2K353LR.js.map +0 -1
  85. package/dist/chunk-JKVD5LHZ.js +0 -2
  86. package/dist/chunk-JKVD5LHZ.js.map +0 -1
  87. package/dist/chunk-NWQ4N5RX.js +0 -2
  88. package/dist/chunk-NWQ4N5RX.js.map +0 -1
  89. package/dist/chunk-PHZ7FTYF.js +0 -2
  90. package/dist/chunk-PHZ7FTYF.js.map +0 -1
  91. package/dist/chunk-PNZTVQA7.js +0 -2
  92. package/dist/chunk-PNZTVQA7.js.map +0 -1
  93. package/dist/chunk-R4JB5MBR.js +0 -2
  94. package/dist/chunk-R4JB5MBR.js.map +0 -1
  95. package/dist/chunk-VFOAY6XI.js +0 -2
  96. package/dist/chunk-VFOAY6XI.js.map +0 -1
  97. package/dist/chunk-XB5BQIEX.js +0 -2
  98. package/dist/chunk-XB5BQIEX.js.map +0 -1
  99. package/dist/core/index.cjs +0 -2
  100. package/dist/core/index.cjs.map +0 -1
  101. package/dist/core/index.d.cts +0 -19
  102. package/dist/core/index.d.ts +0 -19
  103. package/dist/core/index.js +0 -2
  104. package/dist/core/index.js.map +0 -1
  105. package/dist/index.cjs.map +0 -1
  106. package/dist/index.d.cts +0 -84
  107. package/dist/index.js.map +0 -1
  108. package/dist/stream/adapter.cjs +0 -2
  109. package/dist/stream/adapter.cjs.map +0 -1
  110. package/dist/stream/adapter.d.cts +0 -63
  111. package/dist/stream/adapter.d.ts +0 -63
  112. package/dist/stream/adapter.js +0 -2
  113. package/dist/stream/adapter.js.map +0 -1
  114. package/dist/stream/fs-utils.cjs +0 -2
  115. package/dist/stream/fs-utils.cjs.map +0 -1
  116. package/dist/stream/fs-utils.d.cts +0 -137
  117. package/dist/stream/fs-utils.d.ts +0 -137
  118. package/dist/stream/fs-utils.js +0 -2
  119. package/dist/stream/fs-utils.js.map +0 -1
  120. package/dist/stream/index.cjs +0 -2
  121. package/dist/stream/index.cjs.map +0 -1
  122. package/dist/stream/index.d.cts +0 -4
  123. package/dist/stream/index.d.ts +0 -4
  124. package/dist/stream/index.js +0 -2
  125. package/dist/stream/index.js.map +0 -1
  126. package/dist/stream/light/index.cjs +0 -2
  127. package/dist/stream/light/index.cjs.map +0 -1
  128. package/dist/stream/light/index.d.cts +0 -4
  129. package/dist/stream/light/index.d.ts +0 -4
  130. package/dist/stream/light/index.js +0 -2
  131. package/dist/stream/light/index.js.map +0 -1
  132. package/dist/stream/md5-stream.cjs.map +0 -1
  133. package/dist/stream/md5-stream.js.map +0 -1
  134. package/dist/stream/whatwg-stream.cjs.map +0 -1
  135. package/dist/stream/whatwg-stream.js.map +0 -1
  136. package/dist/types-edGoGJ5V.d.cts +0 -42
  137. package/dist/types-edGoGJ5V.d.ts +0 -42
  138. package/dist/utils/detect.cjs.map +0 -1
  139. package/dist/utils/detect.js.map +0 -1
  140. package/planning/03-optimization-size-tree-shaking/01-es-modules-tree-shaking.md +0 -152
  141. package/planning/03-optimization-size-tree-shaking/02-consolidate-modules.md +0 -65
  142. package/planning/03-optimization-size-tree-shaking/03-remove-duplicate-add32.md +0 -93
  143. package/planning/03-optimization-size-tree-shaking/04-remove-runtime-check.md +0 -102
  144. package/planning/03-optimization-size-tree-shaking/05-optimize-loops-performance.md +0 -107
  145. package/planning/03-optimization-size-tree-shaking/06-tsup-formats-configuration.md +0 -227
  146. package/planning/03-optimization-size-tree-shaking/07-multiple-build-formats.md +0 -228
  147. package/planning/03-optimization-size-tree-shaking/08-benchmarks-metrics.md +0 -34
  148. package/planning/03-optimization-size-tree-shaking/MIGRATION_GUIDE.md +0 -260
  149. package/planning/03-optimization-size-tree-shaking/README.md +0 -173
  150. package/planning/03-optimization-size-tree-shaking/SUMMARY.md +0 -168
  151. package/planning/04-adapter-backend/03-backend-web-crypto.md +0 -149
  152. package/planning/04-adapter-backend/04-backend-node-crypto.md +0 -181
  153. package/planning/04-adapter-backend/05-backend-pure-js.md +0 -174
  154. package/planning/04-adapter-backend/06-backend-ie11.md +0 -158
  155. package/planning/04-adapter-backend/07-detection-environment.md +0 -232
  156. package/planning/04-adapter-backend/08-detection-backend.md +0 -210
  157. package/planning/04-adapter-backend/09-adapter-unified.md +0 -255
  158. package/planning/04-adapter-backend/10-fallback-mechanism.md +0 -333
  159. package/planning/04-adapter-backend/11-tests-backend-web-crypto.md +0 -191
  160. package/planning/04-adapter-backend/12-tests-backend-node-crypto.md +0 -222
  161. package/planning/04-adapter-backend/README.md +0 -45
  162. package/planning/05-documentation-publishing/01-README-optimization.md +0 -105
  163. package/planning/05-documentation-publishing/02-VitePress-site-evaluation.md +0 -136
  164. package/planning/05-documentation-publishing/03-Changeset-setup.md +0 -192
  165. package/planning/05-documentation-publishing/04-GitHub-templates.md +0 -252
  166. package/planning/05-documentation-publishing/README.md +0 -22
  167. package/planning/05-documentation-publishing/STATUS.md +0 -222
  168. package/planning/prd.md +0 -405
  169. package/planning/streams/01-create-md5stream-class.md +0 -69
  170. package/planning/streams/02-create-factory-api.md +0 -65
  171. package/planning/streams/03-fs-integration.md +0 -37
  172. package/planning/streams/04-whatwg-streams-support.md +0 -37
  173. package/planning/streams/05-audit-optimization.md +0 -121
  174. package/planning/streams/06-comprehensive-tests-docs.md +0 -137
  175. package/planning/streams/07-architecture-integration.md +0 -38
  176. package/planning/streams/README.md +0 -98
  177. package/tsup.config.ts +0 -24
@@ -1,418 +0,0 @@
1
- import { MD5Stream, createMD5Stream } from '../../src/stream/md5-stream.js';
2
- import { md5Core } from '../../src/core/index.js';
3
-
4
- describe('MD5Stream', () => {
5
- test('should compute MD5 hash for empty string', (done) => {
6
- const stream = new MD5Stream();
7
- const chunks: string[] = [];
8
-
9
- stream.on('data', (chunk) => chunks.push(chunk.toString()));
10
- stream.on('md5', (result) => {
11
- expect(result.digest).toBe(md5Core(''));
12
- expect(result.bytesProcessed).toBe(0);
13
- done();
14
- });
15
-
16
- stream.end('');
17
- });
18
-
19
- test('should compute MD5 hash for simple string', (done) => {
20
- const stream = new MD5Stream();
21
- const input = 'hello';
22
-
23
- stream.on('md5', (result) => {
24
- expect(result.digest).toBe(md5Core(input));
25
- expect(result.bytesProcessed).toBe(input.length);
26
- done();
27
- });
28
-
29
- stream.end(input);
30
- });
31
-
32
- test('should compute MD5 hash for longer string', (done) => {
33
- const stream = new MD5Stream();
34
- const input = 'a'.repeat(1000);
35
-
36
- stream.on('md5', (result) => {
37
- expect(result.digest).toBe(md5Core(input));
38
- expect(result.bytesProcessed).toBe(input.length);
39
- done();
40
- });
41
-
42
- stream.end(input);
43
- });
44
-
45
- test('should process chunked data correctly', (done) => {
46
- const stream = new MD5Stream();
47
- const input = 'hello world';
48
- const chunk1 = 'hello ';
49
- const chunk2 = 'world';
50
-
51
- stream.on('md5', (result) => {
52
- expect(result.digest).toBe(md5Core(input));
53
- expect(result.bytesProcessed).toBe(input.length);
54
- done();
55
- });
56
-
57
- stream.write(chunk1);
58
- stream.write(chunk2);
59
- stream.end();
60
- });
61
-
62
- test('should handle multiple chunks of varying sizes', (done) => {
63
- const stream = new MD5Stream();
64
- const input = 'This is a test string with multiple chunks';
65
- const chunks = ['This ', 'is a', ' test', ' string', ' with', ' multi', 'ple c', 'hunks'];
66
-
67
- stream.on('md5', (result) => {
68
- expect(result.digest).toBe(md5Core(input));
69
- expect(result.bytesProcessed).toBe(input.length);
70
- done();
71
- });
72
-
73
- chunks.forEach(chunk => stream.write(chunk));
74
- stream.end();
75
- });
76
-
77
- test('should handle data that exactly fills 64-byte blocks', (done) => {
78
- const stream = new MD5Stream();
79
- const input = 'a'.repeat(64);
80
-
81
- stream.on('md5', (result) => {
82
- expect(result.digest).toBe(md5Core(input));
83
- expect(result.bytesProcessed).toBe(input.length);
84
- done();
85
- });
86
-
87
- stream.end(input);
88
- });
89
-
90
- test('should handle data that is multiple of 64 bytes', (done) => {
91
- const stream = new MD5Stream();
92
- const input = 'a'.repeat(128);
93
-
94
- stream.on('md5', (result) => {
95
- expect(result.digest).toBe(md5Core(input));
96
- expect(result.bytesProcessed).toBe(input.length);
97
- done();
98
- });
99
-
100
- stream.end(input);
101
- });
102
-
103
- test('should handle special characters', (done) => {
104
- const stream = new MD5Stream();
105
- const input = '!@#$%^&*()_+-=[]{}|;:,.<>?';
106
-
107
- stream.on('md5', (result) => {
108
- expect(result.digest).toBe(md5Core(input));
109
- expect(result.bytesProcessed).toBe(input.length);
110
- done();
111
- });
112
-
113
- stream.end(input);
114
- });
115
-
116
- test('should emit bytesProcessed correctly', (done) => {
117
- const stream = new MD5Stream();
118
- const totalBytes = 256;
119
-
120
- stream.on('md5', (result) => {
121
- expect(result.bytesProcessed).toBe(totalBytes);
122
- done();
123
- });
124
-
125
- // Write data in 64-byte chunks
126
- const chunk = 'a'.repeat(64);
127
- for (let i = 0; i < 4; i++) {
128
- stream.write(chunk);
129
- }
130
- stream.end();
131
- });
132
-
133
- test('should handle binary buffer input', (done) => {
134
- const stream = new MD5Stream();
135
- const input = Buffer.from('test buffer');
136
-
137
- stream.on('md5', (result) => {
138
- // MD5 of string 'test buffer'
139
- expect(result.digest).toBe(md5Core('test buffer'));
140
- expect(result.bytesProcessed).toBe(input.length);
141
- done();
142
- });
143
-
144
- stream.end(input);
145
- });
146
-
147
- test('should handle large file simulation', (done) => {
148
- const stream = new MD5Stream();
149
- const chunkSize = 1024 * 1024; // 1MB
150
- const numChunks = 3;
151
- const totalBytes = chunkSize * numChunks;
152
-
153
- stream.on('md5', (result) => {
154
- // We're just testing that it processes the data without crashing
155
- // The actual hash doesn't matter for this test
156
- expect(result.bytesProcessed).toBe(totalBytes);
157
- expect(result.digest.length).toBe(32); // MD5 is 32 hex chars
158
- done();
159
- });
160
-
161
- const chunk = Buffer.alloc(chunkSize, 'a');
162
- for (let i = 0; i < numChunks; i++) {
163
- stream.write(chunk);
164
- }
165
- stream.end();
166
- });
167
-
168
- test('should support factory function createMD5Stream', (done) => {
169
- const stream = createMD5Stream();
170
- const input = 'factory test';
171
-
172
- stream.on('md5', (result) => {
173
- expect(result.digest).toBe(md5Core(input));
174
- expect(result.bytesProcessed).toBe(input.length);
175
- done();
176
- });
177
-
178
- stream.end(input);
179
- });
180
-
181
- test('should support custom add32 function', (done) => {
182
- const customAdd32 = (x: number, y: number) => (x + y) & 0xffffffff;
183
- const stream = new MD5Stream({ add32: customAdd32 });
184
- const input = 'custom add32 test';
185
-
186
- stream.on('md5', (result) => {
187
- // Should produce the same result as md5Core with default add32
188
- expect(result.digest).toBe(md5Core(input));
189
- expect(result.bytesProcessed).toBe(input.length);
190
- done();
191
- });
192
-
193
- stream.end(input);
194
- });
195
-
196
- test('should handle sequential processing', (done) => {
197
- const stream = new MD5Stream();
198
- const parts = ['Hello, ', 'World!', ' This is ', 'MD5 streaming.'];
199
- const full = parts.join('');
200
-
201
- stream.on('md5', (result) => {
202
- expect(result.digest).toBe(md5Core(full));
203
- expect(result.bytesProcessed).toBe(full.length);
204
- done();
205
- });
206
-
207
- parts.forEach(part => stream.write(part));
208
- stream.end();
209
- });
210
-
211
- test('should handle single byte chunks', (done) => {
212
- const stream = new MD5Stream();
213
- const input = 'a';
214
-
215
- stream.on('md5', (result) => {
216
- expect(result.digest).toBe(md5Core(input));
217
- expect(result.bytesProcessed).toBe(input.length);
218
- done();
219
- });
220
-
221
- stream.write('a');
222
- stream.end();
223
- });
224
-
225
- test('should emit valid hex digest', (done) => {
226
- const stream = new MD5Stream();
227
-
228
- stream.on('md5', (result) => {
229
- // MD5 digest should be 32 hex characters
230
- expect(result.digest).toMatch(/^[0-9a-f]{32}$/);
231
- expect(result.digest.length).toBe(32);
232
- done();
233
- });
234
-
235
- stream.end('test');
236
- });
237
-
238
- test('should reset state properly', (done) => {
239
- const stream = new MD5Stream();
240
- let firstResult: any = null;
241
-
242
- // First computation
243
- stream.on('md5', (result: any) => {
244
- firstResult = result;
245
-
246
- // Destroy and recreate the stream
247
- stream.destroy();
248
- const newStream = new MD5Stream();
249
-
250
- newStream.on('md5', (secondResult: any) => {
251
- // Results should be different
252
- expect(firstResult.digest).not.toBe(secondResult.digest);
253
- expect(firstResult.bytesProcessed).toBe(5); // 'first'.length
254
- expect(secondResult.bytesProcessed).toBe(6); // 'second'.length
255
- done();
256
- });
257
-
258
- newStream.write('second');
259
- newStream.end();
260
- });
261
-
262
- stream.write('first');
263
- stream.end();
264
- });
265
-
266
- test('should get current state during processing', () => {
267
- const stream = new MD5Stream();
268
-
269
- // Check initial state
270
- const initialState = stream.getCurrentState();
271
- expect(initialState.state).toHaveLength(4);
272
- expect(initialState.bytesProcessed).toBe(0);
273
-
274
- // Process some data
275
- stream.write('test');
276
-
277
- const afterDataState = stream.getCurrentState();
278
- expect(afterDataState.bytesProcessed).toBe(4);
279
-
280
- // Check bytes processed getter
281
- expect(stream.getBytesProcessed()).toBe(4);
282
- });
283
-
284
- test('should handle empty chunks', (done) => {
285
- const stream = new MD5Stream();
286
- const input = 'test';
287
-
288
- stream.on('md5', (result) => {
289
- expect(result.digest).toBe(md5Core(input));
290
- expect(result.bytesProcessed).toBe(input.length);
291
- done();
292
- });
293
-
294
- stream.write('');
295
- stream.write('test');
296
- stream.end();
297
- });
298
- });
299
-
300
- import { Readable } from 'stream';
301
-
302
- describe('pipeThroughMD5 and fromStream', () => {
303
- test('should support pipeThroughMD5 method', async () => {
304
- const { pipeThroughMD5 } = await import('../../src/stream/md5-stream.js');
305
- const { md5Core } = await import('../../src/core/index.js');
306
-
307
- const stream = new MD5Stream();
308
- const input = 'pipe through test';
309
- const source = Readable.from([input]);
310
-
311
- const result = await pipeThroughMD5.call(stream, source);
312
-
313
- expect(result.digest).toBe(md5Core(input));
314
- expect(result.bytesProcessed).toBe(input.length);
315
- });
316
-
317
- test('should support fromStream static method', async () => {
318
- const { fromStream } = await import('../../src/stream/md5-stream.js');
319
- const { md5Core } = await import('../../src/core/index.js');
320
-
321
- const input = 'from stream test';
322
- const source = Readable.from([input]);
323
-
324
- const { stream, result } = fromStream(source);
325
-
326
- expect(stream).toBeInstanceOf(MD5Stream);
327
-
328
- const resultData = await result;
329
- expect(resultData.digest).toBe(md5Core(input));
330
- expect(resultData.bytesProcessed).toBe(input.length);
331
- });
332
-
333
- test('should support fromStream with options', async () => {
334
- const { fromStream } = await import('../../src/stream/md5-stream.js');
335
- const { md5Core } = await import('../../src/core/index.js');
336
-
337
- const input = 'from stream with options test';
338
- const source = Readable.from([input]);
339
- const customAdd32 = (x: number, y: number) => (x + y) & 0xffffffff;
340
-
341
- const { result } = fromStream(source, { add32: customAdd32 });
342
-
343
- const resultData = await result;
344
- expect(resultData.digest).toBe(md5Core(input));
345
- expect(resultData.bytesProcessed).toBe(input.length);
346
- });
347
-
348
- test('should handle empty stream with pipeThroughMD5', async () => {
349
- const { pipeThroughMD5 } = await import('../../src/stream/md5-stream.js');
350
- const { md5Core } = await import('../../src/core/index.js');
351
-
352
- const stream = new MD5Stream();
353
- const source = Readable.from([]);
354
-
355
- const result = await pipeThroughMD5.call(stream, source);
356
-
357
- expect(result.digest).toBe(md5Core(''));
358
- expect(result.bytesProcessed).toBe(0);
359
- });
360
-
361
- test('should handle large data with pipeThroughMD5', async () => {
362
- const { pipeThroughMD5 } = await import('../../src/stream/md5-stream.js');
363
- const { md5Core } = await import('../../src/core/index.js');
364
-
365
- const stream = new MD5Stream();
366
- const input = 'a'.repeat(10000);
367
- const source = Readable.from([input]);
368
-
369
- const result = await pipeThroughMD5.call(stream, source);
370
-
371
- expect(result.digest).toBe(md5Core(input));
372
- expect(result.bytesProcessed).toBe(input.length);
373
- });
374
-
375
- test('should handle chunked data with fromStream', async () => {
376
- const { fromStream } = await import('../../src/stream/md5-stream.js');
377
- const { md5Core } = await import('../../src/core/index.js');
378
-
379
- const input = 'chunked data test';
380
- const chunks = ['chunked ', 'data ', 'test'];
381
- const source = Readable.from(chunks);
382
-
383
- const { result } = fromStream(source);
384
-
385
- const resultData = await result;
386
- expect(resultData.digest).toBe(md5Core(input));
387
- expect(resultData.bytesProcessed).toBe(input.length);
388
- });
389
-
390
- test('should support MD5Stream.fromStream static method', async () => {
391
- const { md5Core } = await import('../../src/core/index.js');
392
-
393
- const input = 'static fromStream test';
394
- const source = Readable.from([input]);
395
-
396
- const { stream, result } = MD5Stream.fromStream(source);
397
-
398
- expect(stream).toBeInstanceOf(MD5Stream);
399
-
400
- const resultData = await result;
401
- expect(resultData.digest).toBe(md5Core(input));
402
- expect(resultData.bytesProcessed).toBe(input.length);
403
- });
404
-
405
- test('should support MD5Stream.fromStream with options', async () => {
406
- const { md5Core } = await import('../../src/core/index.js');
407
-
408
- const input = 'static fromStream with options test';
409
- const source = Readable.from([input]);
410
- const customAdd32 = (x: number, y: number) => (x + y) & 0xffffffff;
411
-
412
- const { result } = MD5Stream.fromStream(source, { add32: customAdd32 });
413
-
414
- const resultData = await result;
415
- expect(resultData.digest).toBe(md5Core(input));
416
- expect(resultData.bytesProcessed).toBe(input.length);
417
- });
418
- });