pure-md5 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -3,12 +3,9 @@
3
3
  **A lightweight, zero-dependency JavaScript library for MD5 hashing with streaming support for large files.**
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/pure-md5.svg?style=flat&color=informational)](https://npmjs.org/package/pure-md5)
6
- [![npm downloads](https://img.shields.io/npm/dm/pure-md5.svg?style=flat&color=blue)](https://npmjs.org/package/pure-md5)
6
+ [![npm downloads](https://img.shields.io/npm/dw/pure-md5.svg?style=flat&color=blue)](https://npmjs.org/package/pure-md5)
7
+ [![Coverage Status](https://coveralls.io/repos/github/eustatos/pure-md5/badge.svg?branch=main)](https://coveralls.io/github/eustatos/pure-md5?branch=main)
7
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
8
- [![Build Status](https://img.shields.io/github/actions/workflow/status/eustatos/pure-md5/npm-publish.yml?branch=main&style=flat&logo=github)](https://github.com/eustatos/pure-md5/actions/workflows/npm-publish.yml)
9
- [![codecov](https://img.shields.io/codecov/c/github/eustatos/pure-md5/main?style=flat&logo=codecov)](https://codecov.io/gh/eustatos/pure-md5)
10
- [![Bundle Size](https://img.shields.io/bundlephobia/minzip/pure-md5?style=flat&color=success&label=.bundle%20size)](https://bundlephobia.com/result?p=pure-md5)
11
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.6+-blue?style=flat&logo=typescript)](https://www.typescriptlang.org/)
12
9
 
13
10
  ---
14
11
 
@@ -27,7 +24,7 @@ pnpm add pure-md5
27
24
  ### Basic Usage
28
25
 
29
26
  ```javascript
30
- import { md5 } from 'pure-md5';
27
+ import { md5 } from 'pure-md5/md5';
31
28
 
32
29
  const hash = md5('hello');
33
30
  console.log(hash); // "5d41402abc4b2a76b9719d911017c592"
@@ -50,7 +47,7 @@ fs.createReadStream('large-file.bin').pipe(stream);
50
47
  ## ✨ Features
51
48
 
52
49
  - ⚡ **Zero Dependencies** - No external dependencies, ever
53
- - 📦 **Tiny Bundle** - < 1KB gzipped
50
+ - 📦 **Tiny Bundle** - ~1.4KB gzipped for md5() only (with tree-shaking), ~6KB for full bundle
54
51
  - 🎯 **Multiple APIs** - Simple, streaming, and promise-based
55
52
  - 🦺 **TypeScript Ready** - Full type definitions included
56
53
  - 🔌 **Adapter System** - Automatic detection (WebCrypto, Node.js, Pure JS)
@@ -80,16 +77,10 @@ fs.createReadStream('large-file.bin').pipe(stream);
80
77
  Compute MD5 hash of a string or buffer.
81
78
 
82
79
  ```javascript
83
- import { md5 } from 'pure-md5';
84
-
85
- // String input
86
- md5('hello'); // "5d41402abc4b2a76b9719d911017c592"
87
-
88
- // Buffer input
89
- md5(Buffer.from('hello')); // "5d41402abc4b2a76b9719d911017c592"
80
+ import { md5 } from 'pure-md5/md5'; // Tree-shakeable, ~1.4KB
90
81
 
91
- // Custom encoding
92
- md5('hello', 'hex'); // "5d41402abc4b2a76b9719d911017c592"
82
+ const hash = md5('hello');
83
+ console.log(hash); // "5d41402abc4b2a76b9719d911017c592"
93
84
  ```
94
85
 
95
86
  ### Streaming API
@@ -199,14 +190,31 @@ console.log('Verified:', isVerified); // true or false
199
190
 
200
191
  ## 📊 Comparison with Alternatives
201
192
 
202
- | Feature | pure-md5 | crypto-js | js-md4 | Node.js crypto |
203
- |---------|----------|-----------|--------|----------------|
204
- | Bundle Size | <1KB | ~4KB | ~2KB | N/A |
205
- | Dependencies | 0 | 0 | 0 | 0 |
206
- | Streaming | | | | |
207
- | Browser Support | ✅ | | | ❌ |
208
- | TypeScript | ✅ | ❌ | ⚠️ | ❌ |
209
- | Zero Config | ✅ | | ❌ | |
193
+ | Feature | pure-md5 | pvorb/node-md5 | crypto-js | js-md4 | Node.js crypto |
194
+ |---------|----------|----------------|-----------|--------|----------------|
195
+ | Bundle Size (md5 only) | ~1.4KB¹ | ~3KB | ~4KB | ~2KB | N/A |
196
+ | Bundle Size (full) | ~6KB¹ | ~3KB | ~4KB | ~2KB | N/A |
197
+ | Dependencies | 0 | 0 | 0 | 0 | 0 |
198
+ | Streaming | ✅ | | | ❌ | ✅ |
199
+ | Browser Support | ✅ | ❌ | | ✅ | ❌ |
200
+ | TypeScript | ✅ | | ❌ | ⚠️ | ❌ |
201
+ | Zero Config | ✅ | ❌² | ✅ | ❌ | ✅ |
202
+ | Tree-shaking | ✅ | ❌ | ❌ | ❌ | N/A |
203
+ | Pure JS (no Node) | ✅ | ❌ | ✅ | ✅ | ❌ |
204
+
205
+ ¹ **With tree-shaking**: Only import what you use!
206
+ ² **Requires Node.js environment** - not browser-compatible
207
+
208
+ ### Why choose pure-md5 over pvorb/node-md5?
209
+
210
+ 1. **Browser Support**: pvorb/node-md5 only works in Node.js, while pure-md5 works everywhere
211
+ 2. **Tree-shaking**: pure-md5 supports modern tree-shaking for smaller bundles
212
+ 3. **Streaming**: built-in streaming API for large files in pure-md5
213
+ 4. **TypeScript**: first-class TypeScript support with full type definitions
214
+ 5. **Zero dependencies**: truly zero-dependency implementation
215
+ 6. **Modern API**: cleaner, more intuitive interface with promise-based options
216
+
217
+ pvorb/node-md5 is still a good choice if you only need Node.js and prefer its API style.
210
218
 
211
219
  ---
212
220
 
@@ -228,12 +236,15 @@ import { md5 } from 'pure-md5';
228
236
 
229
237
  ### Manual Adapter Selection
230
238
 
239
+ Use adapter backends directly when you need explicit control:
240
+
231
241
  ```javascript
232
- import { md5 } from 'pure-md5/adapters/node';
233
- // or
234
- import { md5 } from 'pure-md5/adapters/webcrypto';
235
- // or
236
- import { md5 } from 'pure-md5/adapters/pure-js';
242
+ import { NodeCryptoBackend, WebCryptoBackend, PureJSBackend } from 'pure-md5';
243
+
244
+ // Create backend instances
245
+ const nodeBackend = new NodeCryptoBackend();
246
+ const hash = await nodeBackend.hash('hello');
247
+ console.log(hash);
237
248
  ```
238
249
 
239
250
  ---
@@ -284,6 +295,3 @@ If you find this project helpful, please consider supporting it:
284
295
  - [RFC 1321 - The MD5 Message-Digest Algorithm](https://www.ietf.org/rfc/rfc1321.txt)
285
296
  - [Node.js crypto documentation](https://nodejs.org/api/crypto.html)
286
297
 
287
- ---
288
-
289
- *Made with ❤️ by [Aleksandr Astashkin](https://github.com/eustatos)
@@ -1 +1 @@
1
- export{a as IE11Backend}from'../chunk-QB6MF5LD.js';import'../chunk-I7AUKTXE.js';
1
+ var n=class{constructor(){this.name="ie11";this.version="1.0.0";}static isAvailable(){if(typeof window>"u")return false;let r=window;return typeof r.msCrypto<"u"&&typeof r.msCrypto.subtle<"u"&&typeof r.msCrypto.subtle.digest=="function"}async hash(r){let e=new TextEncoder().encode(r);return await this.hashBinary(e)}async hashBinary(r){let t=window,e=r instanceof Uint8Array?r.buffer:r,i=await t.msCrypto.subtle.digest("MD5",e);return this.bufferToHex(i)}bufferToHex(r){return Array.from(new Uint8Array(r)).map(t=>t.toString(16).padStart(2,"0")).join("")}update(r){throw new Error("msCrypto does not support streaming updates")}digest(r){throw new Error("msCrypto does not support streaming")}reset(){}};export{n as IE11Backend};
@@ -1 +1 @@
1
- export{a as NodeCryptoBackend}from'../chunk-XPYPJSJE.js';import'../chunk-I7AUKTXE.js';
1
+ var n=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(r,t)=>(typeof require<"u"?require:r)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var i=class{constructor(){this.name="nodecrypto";this.version="1.0.0";}static isAvailable(){try{return typeof n("crypto").createHash=="function"}catch{return false}}hash(r){return n("crypto").createHash("md5").update(r).digest("hex")}async hashBinary(r){let t=n("crypto"),o=r instanceof Uint8Array?r:new Uint8Array(r);return t.createHash("md5").update(o).digest("hex")}update(r){}digest(r){throw new Error("Node crypto streaming not implemented")}reset(){}};export{i as NodeCryptoBackend};
@@ -1 +1 @@
1
- export{a as WebCryptoBackend}from'../chunk-43QQAXLT.js';import'../chunk-Z4JB6DTM.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
1
+ var C="0123456789abcdef".split(""),p=C;function B(o){let n="";for(let m=0;m<4;m++)n+=p[o>>m*8+4&15]+p[o>>m*8&15];return n}function P(o){let n=o.length,m=new Array(n);for(let e=0;e<n;e++)m[e]=B(o[e]);return m.join("")}var g=P;function D(o,n){return o+n&4294967295}var c=D;function U(o,n,m,e,r){let t=r||c;return n=t(t(n,o),t(m,e)),n}function _(o,n,m,e){var t=(e||c)(o<<n|o>>>32-n,m);return t}function s(o,n,m,e,r,t,u){return n=U(o,n,e,t,u),_(n,r,m,u)}function h(o,n,m,e,r,t,u,i){return s(m&e|~m&r,n,m,t,u,i,o)}function y(o,n,m,e,r,t,u,i){return s(m&r|e&~r,n,m,t,u,i,o)}function A(o,n,m,e,r,t,u,i){return s(m^e^r,n,m,t,u,i,o)}function x(o,n,m,e,r,t,u,i){return s(e^(m|~r),n,m,t,u,i,o)}function j(o,n,m){typeof m>"u"&&(m=c);let e=o[0],r=o[1],t=o[2],u=o[3],i=h.bind(null,m);e=i(e,r,t,u,n[0],7,-680876936),u=i(u,e,r,t,n[1],12,-389564586),t=i(t,u,e,r,n[2],17,606105819),r=i(r,t,u,e,n[3],22,-1044525330),e=i(e,r,t,u,n[4],7,-176418897),u=i(u,e,r,t,n[5],12,1200080426),t=i(t,u,e,r,n[6],17,-1473231341),r=i(r,t,u,e,n[7],22,-45705983),e=i(e,r,t,u,n[8],7,1770035416),u=i(u,e,r,t,n[9],12,-1958414417),t=i(t,u,e,r,n[10],17,-42063),r=i(r,t,u,e,n[11],22,-1990404162),e=i(e,r,t,u,n[12],7,1804603682),u=i(u,e,r,t,n[13],12,-40341101),t=i(t,u,e,r,n[14],17,-1502002290),r=i(r,t,u,e,n[15],22,1236535329);let d=y.bind(null,m);e=d(e,r,t,u,n[1],5,-165796510),u=d(u,e,r,t,n[6],9,-1069501632),t=d(t,u,e,r,n[11],14,643717713),r=d(r,t,u,e,n[0],20,-373897302),e=d(e,r,t,u,n[5],5,-701558691),u=d(u,e,r,t,n[10],9,38016083),t=d(t,u,e,r,n[15],14,-660478335),r=d(r,t,u,e,n[4],20,-405537848),e=d(e,r,t,u,n[9],5,568446438),u=d(u,e,r,t,n[14],9,-1019803690),t=d(t,u,e,r,n[3],14,-187363961),r=d(r,t,u,e,n[8],20,1163531501),e=d(e,r,t,u,n[13],5,-1444681467),u=d(u,e,r,t,n[2],9,-51403784),t=d(t,u,e,r,n[7],14,1735328473),r=d(r,t,u,e,n[12],20,-1926607734);let b=A.bind(null,m);e=b(e,r,t,u,n[5],4,-378558),u=b(u,e,r,t,n[8],11,-2022574463),t=b(t,u,e,r,n[11],16,1839030562),r=b(r,t,u,e,n[14],23,-35309556),e=b(e,r,t,u,n[1],4,-1530992060),u=b(u,e,r,t,n[4],11,1272893353),t=b(t,u,e,r,n[7],16,-155497632),r=b(r,t,u,e,n[10],23,-1094730640),e=b(e,r,t,u,n[13],4,681279174),u=b(u,e,r,t,n[0],11,-358537222),t=b(t,u,e,r,n[3],16,-722521979),r=b(r,t,u,e,n[6],23,76029189),e=b(e,r,t,u,n[9],4,-640364487),u=b(u,e,r,t,n[12],11,-421815835),t=b(t,u,e,r,n[15],16,530742520),r=b(r,t,u,e,n[2],23,-995338651);let f=x.bind(null,m);e=f(e,r,t,u,n[0],6,-198630844),u=f(u,e,r,t,n[7],10,1126891415),t=f(t,u,e,r,n[14],15,-1416354905),r=f(r,t,u,e,n[5],21,-57434055),e=f(e,r,t,u,n[12],6,1700485571),u=f(u,e,r,t,n[3],10,-1894986606),t=f(t,u,e,r,n[10],15,-1051523),r=f(r,t,u,e,n[1],21,-2054922799),e=f(e,r,t,u,n[8],6,1873313359),u=f(u,e,r,t,n[15],10,-30611744),t=f(t,u,e,r,n[6],15,-1560198380),r=f(r,t,u,e,n[13],21,1309151649),e=f(e,r,t,u,n[4],6,-145523070),u=f(u,e,r,t,n[11],10,-1120210379),t=f(t,u,e,r,n[2],15,718787259),r=f(r,t,u,e,n[9],21,-343485551),o[0]=m(e,o[0]),o[1]=m(r,o[1]),o[2]=m(t,o[2]),o[3]=m(u,o[3]);}var l=j;function E(o){let n=[];for(let m=0;m<64;m+=4)n[m>>2]=(o.charCodeAt(m)||0)+((o.charCodeAt(m+1)||0)<<8)+((o.charCodeAt(m+2)||0)<<16)+((o.charCodeAt(m+3)||0)<<24);return n}var F=E;function I(o,n){let m=o.length,e=[1732584193,-271733879,-1732584194,271733878],r;for(r=64;r<=m;r+=64)l(e,F(o.substring(r-64,r)),n);o=o.substring(r-64);var t=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],u=o.length;for(r=0;r<u;r++)t[r>>2]|=(o.charCodeAt(r)&255)<<(r%4<<3);if(t[r>>2]|=128<<(r%4<<3),r>55)for(l(e,t,n),r=16;r--;)t[r]=0;return t[14]=m*8,l(e,t,n),e}var v=I;function a(o){return g(v(o,c))}var w=class{constructor(){this.name="webcrypto";this.version="1.0.0";}static isAvailable(){return typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.subtle.digest=="function"}async hash(n){return a(n)}async hashBinary(n){let m=n instanceof ArrayBuffer?new TextDecoder().decode(n):new TextDecoder().decode(n);return a(m)}update(n){throw new Error("Web Crypto API does not support streaming updates")}digest(n){throw new Error("Web Crypto API does not support streaming")}reset(){}};export{w as WebCryptoBackend};
package/dist/index.d.ts CHANGED
@@ -1,12 +1,23 @@
1
- export { md5 as md5Core, md5 as md5Original } from './core/index.js';
2
1
  export { WebCryptoBackend } from './adapters/webcrypto.js';
3
2
  export { NodeCryptoBackend } from './adapters/node.js';
4
3
  export { IE11Backend } from './adapters/ie11.js';
5
4
  import { M as MD5Backend } from './types-edGoGJ5V.js';
6
- export { MD5Result, MD5Stream, createMD5Stream, fromStream, pipeThroughMD5 } from './stream/md5-stream.js';
7
- export { HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile } from './stream/fs-utils.js';
5
+ import { MD5Result } from './stream/md5-stream.js';
6
+ export { MD5Stream, createMD5Stream, fromStream, pipeThroughMD5 } from './stream/md5-stream.js';
7
+ import { Readable } from 'stream';
8
8
  export { BackendDetector, FallbackManager, MetricsCollector, detector, fallbackManager, getAllAvailableBackends, getBestAvailableBackend, metrics, robustHash } from './utils/detect.js';
9
- import 'stream';
9
+
10
+ /**
11
+ * Core MD5 implementation - Pure JavaScript
12
+ * No dependencies, no environment detection
13
+ * This is the minimal, tree-shakeable core
14
+ */
15
+ /**
16
+ * Compute MD5 hash of a string
17
+ * @param string - Input string to hash
18
+ * @returns MD5 hash as hex string
19
+ */
20
+ declare function md5Core(string: string): string;
10
21
 
11
22
  /**
12
23
  * Pure JavaScript Backend
@@ -27,6 +38,139 @@ declare class PureJSBackend implements MD5Backend {
27
38
  private hexToBuffer;
28
39
  }
29
40
 
41
+ /**
42
+ * File System Utilities for MD5 hashing
43
+ * Provides convenient utilities for hashing files through Node.js file system streams
44
+ */
45
+
46
+ /**
47
+ * Options for file hashing operations
48
+ */
49
+ interface HashFileOptions {
50
+ /**
51
+ * Chunk size for reading file (default: 64KB)
52
+ */
53
+ chunkSize?: number;
54
+ /**
55
+ * Progress callback for tracking hashing progress
56
+ * @param current - Current position in bytes
57
+ */
58
+ onProgress?: (current: number) => void;
59
+ }
60
+ /**
61
+ * Hash a file by its path
62
+ * @param filePath - Path to the file to hash
63
+ * @param options - Optional configuration
64
+ * @returns Promise with MD5 result (digest and bytes processed)
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import { hashFile } from 'pure-md5';
69
+ *
70
+ * const result = await hashFile('path/to/file.txt');
71
+ * console.log('MD5:', result.digest);
72
+ * console.log('Bytes:', result.bytesProcessed);
73
+ * ```
74
+ */
75
+ declare function hashFile(filePath: string, options?: HashFileOptions): Promise<MD5Result>;
76
+ /**
77
+ * Hash data from an existing readable stream
78
+ * @param readStream - Readable stream to hash
79
+ * @param options - Optional configuration
80
+ * @returns Promise with MD5 result (digest and bytes processed)
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { createReadStream } from 'fs';
85
+ * import { hashFileStream } from 'pure-md5';
86
+ *
87
+ * const stream = createReadStream('path/to/file.txt');
88
+ * const result = await hashFileStream(stream);
89
+ * console.log('MD5:', result.digest);
90
+ * ```
91
+ */
92
+ declare function hashFileStream(readStream: Readable, options?: {
93
+ onProgress?: (current: number) => void;
94
+ totalSize?: number;
95
+ }): Promise<MD5Result>;
96
+ /**
97
+ * Hash a file and return only the hex digest
98
+ * @param filePath - Path to the file to hash
99
+ * @param options - Optional configuration
100
+ * @returns Promise with MD5 hex digest string
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { hashFileDigest } from 'pure-md5';
105
+ *
106
+ * const digest = await hashFileDigest('path/to/file.txt');
107
+ * console.log('MD5:', digest);
108
+ * ```
109
+ */
110
+ declare function hashFileDigest(filePath: string, options?: HashFileOptions): Promise<string>;
111
+ /**
112
+ * Hash a file stream and return only the hex digest
113
+ * @param readStream - Readable stream to hash
114
+ * @param options - Optional configuration
115
+ * @returns Promise with MD5 hex digest string
116
+ */
117
+ declare function hashFileStreamDigest(readStream: Readable, options?: {
118
+ onProgress?: (current: number) => void;
119
+ totalSize?: number;
120
+ }): Promise<string>;
121
+ /**
122
+ * Verify file integrity by comparing MD5 hash
123
+ * @param filePath - Path to the file to verify
124
+ * @param expectedDigest - Expected MD5 hex digest
125
+ * @param options - Optional configuration
126
+ * @returns Promise with verification result
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { verifyFile } from 'pure-md5';
131
+ *
132
+ * const isVerified = await verifyFile(
133
+ * 'path/to/file.txt',
134
+ * '5d41402abc4b2a76b9719d911017c592'
135
+ * );
136
+ * console.log('Verified:', isVerified);
137
+ * ```
138
+ */
139
+ declare function verifyFile(filePath: string, expectedDigest: string, options?: HashFileOptions): Promise<boolean>;
140
+ /**
141
+ * Get MD5 hash of a file synchronously (not recommended for large files)
142
+ * @param filePath - Path to the file to hash
143
+ * @returns MD5 hex digest string
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * import { hashFileSync } from 'pure-md5';
148
+ *
149
+ * const digest = hashFileSync('path/to/file.txt');
150
+ * console.log('MD5:', digest);
151
+ * ```
152
+ */
153
+ declare function hashFileSync(filePath: string): string;
154
+ /**
155
+ * Utility to create a progress tracker for file hashing
156
+ * @param totalSize - Total size of the file being hashed
157
+ * @param onUpdate - Callback with progress percentage (0-100)
158
+ * @returns Progress callback function
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * import { hashFile, createProgressTracker } from 'pure-md5';
163
+ *
164
+ * const totalSize = 1024 * 1024 * 100; // 100MB
165
+ * const progress = createProgressTracker(totalSize, (percent) => {
166
+ * console.log(`Progress: ${percent.toFixed(1)}%`);
167
+ * });
168
+ *
169
+ * const result = await hashFile('large-file.bin', { onProgress: progress });
170
+ * ```
171
+ */
172
+ declare function createProgressTracker(totalSize: number, onUpdate: (percentage: number) => void): (current: number) => void;
173
+
30
174
  /**
31
175
  * Pure MD5 - Unified adapter with auto-detection
32
176
  * Supports multiple backends: Web Crypto, Node.js crypto, IE11, and Pure JS
@@ -81,4 +225,4 @@ declare function md5(data: string): string;
81
225
  declare const md5Adapter: MD5Adapter;
82
226
  declare function md5Async(data: string): Promise<string>;
83
227
 
84
- export { MD5Backend, PureJSBackend, md5, md5Adapter, md5Async };
228
+ export { type HashFileOptions, MD5Backend, MD5Result, PureJSBackend, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, md5, md5Adapter, md5Async, md5Core, md5Core as md5Original, verifyFile };
package/dist/index.js CHANGED
@@ -1 +1,3 @@
1
- import'./chunk-374HUUY2.js';import'./chunk-BEGGPFEE.js';import {h,j}from'./chunk-4F2Y3CRO.js';export{k as BackendDetector,m as FallbackManager,p as MetricsCollector,a as PureJSBackend,l as detector,n as fallbackManager,h as getAllAvailableBackends,j as getBestAvailableBackend,q as metrics,o as robustHash}from'./chunk-4F2Y3CRO.js';import {a as a$2}from'./chunk-QB6MF5LD.js';export{a as IE11Backend}from'./chunk-QB6MF5LD.js';import {a as a$4}from'./chunk-XPYPJSJE.js';export{a as NodeCryptoBackend}from'./chunk-XPYPJSJE.js';import {a as a$3}from'./chunk-43QQAXLT.js';export{a as WebCryptoBackend}from'./chunk-43QQAXLT.js';import {a as a$1}from'./chunk-Y2ZKN4NS.js';export{g as createProgressTracker,a as hashFile,c as hashFileDigest,b as hashFileStream,d as hashFileStreamDigest,f as hashFileSync,e as verifyFile}from'./chunk-YDAOGTNB.js';import {a}from'./chunk-Z4JB6DTM.js';export{a as md5Core,a as md5Original}from'./chunk-Z4JB6DTM.js';export{a as MD5Stream,b as createMD5Stream,d as fromStream,c as pipeThroughMD5}from'./chunk-MIU3X4SB.js';import'./chunk-DFR4GYL3.js';import'./chunk-I7AUKTXE.js';var d=class{constructor(){this.backend=null;this.backendName=null;}async hash(e){return (await this.getBackend()).hash(e)}async hashBinary(e){return (await this.getBackend()).hashBinary(e)}async getBackendName(){if(!this.backendName){let e=await h();this.backendName=j(e);}return this.backendName}static async getAvailableBackends(){return await h()}async useBackend(e){this.backend=await this.createBackendByName(e),this.backendName=e;}async createBackendByName(e){switch(e){case "nodecrypto":return new a$4;case "webcrypto":return new a$3;case "ie11":return new a$2;case "stream":return new a$1;default:return {hash:a$1=>a(a$1),hashBinary:async a$1=>a(a$1 instanceof Uint8Array?new TextDecoder().decode(a$1):new TextDecoder().decode(new Uint8Array(a$1))),update:()=>{},digest:()=>"",reset:()=>{},name:"purejs",version:"0.1.0"}}}async getBackend(){if(this.backend)return this.backend;let e=await h(),a=j(e);return this.backend=await this.createBackendByName(a),this.backendName=a,this.backend}};function I(n){return a(n)}var S=new d;async function O(n){return S.hash(n)}export{I as md5,S as md5Adapter,O as md5Async};
1
+ import {Transform}from'stream';import D from'fs';var N=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var Z="0123456789abcdef".split(""),O=Z;function ee(i){let e="";for(let n=0;n<4;n++)e+=O[i>>n*8+4&15]+O[i>>n*8&15];return e}function re(i){let e=i.length,n=new Array(e);for(let r=0;r<e;r++)n[r]=ee(i[r]);return n.join("")}var S=re;function te(i,e){return i+e&4294967295}var b=te;function ne(i,e,n,r,t){let s=t||b;return e=s(s(e,i),s(n,r)),e}function se(i,e,n,r){var s=(r||b)(i<<e|i>>>32-e,n);return s}function C(i,e,n,r,t,s,a){return e=ne(i,e,r,s,a),se(e,t,n,a)}function I(i,e,n,r,t,s,a,o){return C(n&r|~n&t,e,n,s,a,o,i)}function L(i,e,n,r,t,s,a,o){return C(n&t|r&~t,e,n,s,a,o,i)}function $(i,e,n,r,t,s,a,o){return C(n^r^t,e,n,s,a,o,i)}function _(i,e,n,r,t,s,a,o){return C(r^(n|~t),e,n,s,a,o,i)}function ie(i,e,n){typeof n>"u"&&(n=b);let r=i[0],t=i[1],s=i[2],a=i[3],o=I.bind(null,n);r=o(r,t,s,a,e[0],7,-680876936),a=o(a,r,t,s,e[1],12,-389564586),s=o(s,a,r,t,e[2],17,606105819),t=o(t,s,a,r,e[3],22,-1044525330),r=o(r,t,s,a,e[4],7,-176418897),a=o(a,r,t,s,e[5],12,1200080426),s=o(s,a,r,t,e[6],17,-1473231341),t=o(t,s,a,r,e[7],22,-45705983),r=o(r,t,s,a,e[8],7,1770035416),a=o(a,r,t,s,e[9],12,-1958414417),s=o(s,a,r,t,e[10],17,-42063),t=o(t,s,a,r,e[11],22,-1990404162),r=o(r,t,s,a,e[12],7,1804603682),a=o(a,r,t,s,e[13],12,-40341101),s=o(s,a,r,t,e[14],17,-1502002290),t=o(t,s,a,r,e[15],22,1236535329);let c=L.bind(null,n);r=c(r,t,s,a,e[1],5,-165796510),a=c(a,r,t,s,e[6],9,-1069501632),s=c(s,a,r,t,e[11],14,643717713),t=c(t,s,a,r,e[0],20,-373897302),r=c(r,t,s,a,e[5],5,-701558691),a=c(a,r,t,s,e[10],9,38016083),s=c(s,a,r,t,e[15],14,-660478335),t=c(t,s,a,r,e[4],20,-405537848),r=c(r,t,s,a,e[9],5,568446438),a=c(a,r,t,s,e[14],9,-1019803690),s=c(s,a,r,t,e[3],14,-187363961),t=c(t,s,a,r,e[8],20,1163531501),r=c(r,t,s,a,e[13],5,-1444681467),a=c(a,r,t,s,e[2],9,-51403784),s=c(s,a,r,t,e[7],14,1735328473),t=c(t,s,a,r,e[12],20,-1926607734);let u=$.bind(null,n);r=u(r,t,s,a,e[5],4,-378558),a=u(a,r,t,s,e[8],11,-2022574463),s=u(s,a,r,t,e[11],16,1839030562),t=u(t,s,a,r,e[14],23,-35309556),r=u(r,t,s,a,e[1],4,-1530992060),a=u(a,r,t,s,e[4],11,1272893353),s=u(s,a,r,t,e[7],16,-155497632),t=u(t,s,a,r,e[10],23,-1094730640),r=u(r,t,s,a,e[13],4,681279174),a=u(a,r,t,s,e[0],11,-358537222),s=u(s,a,r,t,e[3],16,-722521979),t=u(t,s,a,r,e[6],23,76029189),r=u(r,t,s,a,e[9],4,-640364487),a=u(a,r,t,s,e[12],11,-421815835),s=u(s,a,r,t,e[15],16,530742520),t=u(t,s,a,r,e[2],23,-995338651);let f=_.bind(null,n);r=f(r,t,s,a,e[0],6,-198630844),a=f(a,r,t,s,e[7],10,1126891415),s=f(s,a,r,t,e[14],15,-1416354905),t=f(t,s,a,r,e[5],21,-57434055),r=f(r,t,s,a,e[12],6,1700485571),a=f(a,r,t,s,e[3],10,-1894986606),s=f(s,a,r,t,e[10],15,-1051523),t=f(t,s,a,r,e[1],21,-2054922799),r=f(r,t,s,a,e[8],6,1873313359),a=f(a,r,t,s,e[15],10,-30611744),s=f(s,a,r,t,e[6],15,-1560198380),t=f(t,s,a,r,e[13],21,1309151649),r=f(r,t,s,a,e[4],6,-145523070),a=f(a,r,t,s,e[11],10,-1120210379),s=f(s,a,r,t,e[2],15,718787259),t=f(t,s,a,r,e[9],21,-343485551),i[0]=n(r,i[0]),i[1]=n(t,i[1]),i[2]=n(s,i[2]),i[3]=n(a,i[3]);}var m=ie;function ae(i){let e=[];for(let n=0;n<64;n+=4)e[n>>2]=(i.charCodeAt(n)||0)+((i.charCodeAt(n+1)||0)<<8)+((i.charCodeAt(n+2)||0)<<16)+((i.charCodeAt(n+3)||0)<<24);return e}var G=ae;function oe(i,e){let n=i.length,r=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=n;t+=64)m(r,G(i.substring(t-64,t)),e);i=i.substring(t-64);var s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=i.length;for(t=0;t<a;t++)s[t>>2]|=(i.charCodeAt(t)&255)<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(m(r,s,e),t=16;t--;)s[t]=0;return s[14]=n*8,m(r,s,e),r}var z=oe;function ce(i,e){let n=i.length,r=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=n;t+=64){let o=ue(i,t-64);m(r,o,e);}let s=n-t+64,a=new Array(16).fill(0);for(let o=0;o<s;o++)a[o>>2]|=(i[n-s+o]&255)<<(o%4<<3);if(a[s>>2]|=128<<(s%4<<3),s>55){m(r,a,e);for(let o=0;o<16;o++)a[o]=0;}return a[14]=n*8,a[15]=0,m(r,a,e),r}function ue(i,e){let n=[];for(let r=0;r<64;r+=4)n[r>>2]=(i[e+r]||0)+((i[e+r+1]||0)<<8)+((i[e+r+2]||0)<<16)+((i[e+r+3]||0)<<24);return n}var K=ce;function l(i){return S(z(i,b))}function q(i){return S(K(i,b))}var g=class{constructor(){this.name="webcrypto";this.version="1.0.0";}static isAvailable(){return typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.subtle.digest=="function"}async hash(e){return l(e)}async hashBinary(e){let n=e instanceof ArrayBuffer?new TextDecoder().decode(e):new TextDecoder().decode(e);return l(n)}update(e){throw new Error("Web Crypto API does not support streaming updates")}digest(e){throw new Error("Web Crypto API does not support streaming")}reset(){}};var w=class{constructor(){this.name="nodecrypto";this.version="1.0.0";}static isAvailable(){try{return typeof N("crypto").createHash=="function"}catch{return false}}hash(e){return N("crypto").createHash("md5").update(e).digest("hex")}async hashBinary(e){let n=N("crypto"),r=e instanceof Uint8Array?e:new Uint8Array(e);return n.createHash("md5").update(r).digest("hex")}update(e){}digest(e){throw new Error("Node crypto streaming not implemented")}reset(){}};var B=class{constructor(){this.name="ie11";this.version="1.0.0";}static isAvailable(){if(typeof window>"u")return false;let e=window;return typeof e.msCrypto<"u"&&typeof e.msCrypto.subtle<"u"&&typeof e.msCrypto.subtle.digest=="function"}async hash(e){let r=new TextEncoder().encode(e);return await this.hashBinary(r)}async hashBinary(e){let n=window,r=e instanceof Uint8Array?e.buffer:e,t=await n.msCrypto.subtle.digest("MD5",r);return this.bufferToHex(t)}bufferToHex(e){return Array.from(new Uint8Array(e)).map(n=>n.toString(16).padStart(2,"0")).join("")}update(e){throw new Error("msCrypto does not support streaming updates")}digest(e){throw new Error("msCrypto does not support streaming")}reset(){}};var p=class i extends Transform{constructor(n){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=n?.add32||b,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(n,r,t){try{let s=n,a=s.length;if(a===0){t();return}if(this.state.bufferLength>0){let u=this.state.bufferLength,f=64-u,h=Math.min(a,f);for(let d=0;d<h;d++)this.buffer[u+d]=s[d];if(this.state.bufferLength+=h,this.state.bufferLength===64&&this._processBufferBlock(),h===a){t();return}let y=a-h;for(let d=0;d<y;d++)s[d]=s[h+d];let v=Buffer.alloc(y);for(let d=0;d<y;d++)v[d]=s[d];s=v;}let o=Math.floor(s.length/64);for(let u=0;u<o;u++){let f=u*64,h=[];for(let y=0;y<16;y++){let v=f+y*4;h[y]=s[v]+(s[v+1]<<8)+(s[v+2]<<16)+(s[v+3]<<24);}m(this.state.state,h,this.add32),this.state.bytesProcessed+=64;}let c=s.length%64;if(c>0){this.buffer.length<c&&(this.buffer=new Uint8Array(c),this.state.buffer=this.buffer);for(let u=0;u<c;u++)this.buffer[u]=s[o*64+u];this.state.bufferLength=c;}t();}catch(s){t(s);}}_processBufferBlock(){let n=this.state.buffer,r=[];for(let t=0;t<16;t++){let s=t*4;r[t]=n[s]+(n[s+1]<<8)+(n[s+2]<<16)+(n[s+3]<<24);}m(this.state.state,r,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(n){try{let{state:r,bufferLength:t,buffer:s}=this.state,a=new Array(16).fill(0);for(let c=0;c<t;c++)a[c>>2]|=(s[c]&255)<<(c%4<<3);if(a[t>>2]|=128<<(t%4<<3),t>55){m(r,a,this.add32);for(let c=0;c<16;c++)a[c]=0;}a[14]=(this.state.bytesProcessed+t)*8,a[15]=0,m(r,a,this.add32);let o=S(r);this.emit("md5",{digest:o,bytesProcessed:this.state.bytesProcessed+t}),n();}catch(r){n(r);}}getCurrentState(){return {state:[...this.state.state],bytesProcessed:this.state.bytesProcessed+this.state.bufferLength}}getBytesProcessed(){return this.state.bytesProcessed+this.state.bufferLength}reset(){this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer},this.buffer=new Uint8Array(this.bufferCapacity),this.state.buffer=this.buffer,this.state.bufferLength=0;}static fromStream(n,r){let t=new i(r),s=E.call(t,n);return {stream:t,result:s}}};function R(i){return new p(i)}async function E(i){return new Promise((e,n)=>{let r=[];i.pipe(this).on("md5",t=>{r.push(t);}).on("error",n).on("finish",()=>{e(r[0]);});})}function j(i,e){let n=new p(e),r=E.call(n,i);return {stream:n,result:r}}var A=class{constructor(){this.name="stream";this.version="0.1.0";this.state=null;}initNodeStream(e){this.state={stream:e,type:"node"};}initWhatWGStream(e){this.state={stream:e,type:"whatwg"};}async hash(e){let n=new p;return (await new Promise((t,s)=>{n.on("md5",a=>t(a)).on("error",s).end(e);})).digest}async hashBinary(e){let n=new p,r;return e instanceof Uint8Array?r=Buffer.from(e):e instanceof ArrayBuffer?r=Buffer.from(new Uint8Array(e)):r=Buffer.from(e),(await new Promise((s,a)=>{n.on("md5",o=>s(o)).on("error",a).end(r);})).digest}update(e){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let n=this.state.stream,r;typeof e=="string"||e instanceof Uint8Array?r=Buffer.from(e):e instanceof ArrayBuffer?r=Buffer.from(new Uint8Array(e)):r=Buffer.from(e),n.write(r);}}digest(e){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let n=this.state.stream;return n.end(),new Promise((r,t)=>{n.on("md5",s=>{if(e==="buffer"){let a=s.digest,o=[];for(let c=0;c<a.length;c+=2)o.push(parseInt(a.substring(c,c+2),16));r(Buffer.from(o));}else r(s.digest);}).on("error",t);})}else return this.state.stream.getResult().then(r=>r.digest)}reset(){this.state&&this.state.type==="node"&&this.state.stream.reset();}static isAvailable(){return true}};var k=class{constructor(){this.name="purejs";this.version="0.1.0";this.state={data:"",finished:false};}hash(e){return l(e)}async hashBinary(e){let n=e instanceof ArrayBuffer?new TextDecoder().decode(e):new TextDecoder().decode(e);return l(n)}update(e){this.state.finished&&(this.state={data:"",finished:false}),e instanceof ArrayBuffer?this.state.data+=new TextDecoder().decode(e):e instanceof Uint8Array?this.state.data+=new TextDecoder().decode(e):this.state.data+=e;}digest(e){let n=l(this.state.data);return this.state.finished=true,e==="buffer"?this.hexToBuffer(n):n}reset(){this.state={data:"",finished:false};}static isAvailable(){return true}hexToBuffer(e){let n=[];for(let r=0;r<e.length;r+=2)n.push(parseInt(e.substring(r,r+2),16));return new Uint8Array(n)}};async function de(i){switch(i){case "webcrypto":let e=g.isAvailable();return {backend:"webcrypto",available:e,reason:e?void 0:"Web Crypto API not available"};case "nodecrypto":let n=w.isAvailable();return {backend:"nodecrypto",available:n,reason:n?void 0:"Node.js crypto not available"};case "ie11":let r=B.isAvailable();return {backend:"ie11",available:r,reason:r?void 0:"IE11 msCrypto not available"};case "purejs":return {backend:"purejs",available:true,reason:"Always available"};case "stream":let t=typeof process<"u"&&process.versions&&"node"in process.versions,s=typeof window<"u";return {backend:"stream",available:t||s,reason:t||s?void 0:"Streams not available"};default:return {backend:i||"unknown",available:false,reason:"Unknown backend"}}}async function x(){let i=["webcrypto","nodecrypto","ie11","purejs","stream"],e=[];for(let n of i){let{available:r}=await de(n);r&&e.push(n);}return e}var me=[{name:"nodecrypto",priority:1,description:"Node.js native crypto (fastest)"},{name:"webcrypto",priority:2,description:"Web Crypto API (fast, hardware accelerated)"},{name:"ie11",priority:3,description:"IE11 msCrypto (legacy)"},{name:"stream",priority:4,description:"Streaming backend (for large files and memory efficiency)"},{name:"purejs",priority:5,description:"Pure JavaScript (always available, slower)"}];function F(i){let e=[...me].sort((n,r)=>n.priority-r.priority);for(let{name:n}of e)if(i.includes(n))return n;return "purejs"}var M=class i{constructor(){}static getInstance(){return i.instance||(i.instance=new i),i.instance}async createBackendByName(e){switch(e){case "nodecrypto":return new w;case "webcrypto":return new g;case "ie11":return new B;case "stream":return new A;default:return new k}}async createBackend(e){let n=e||F(await x());return this.createBackendByName(n)}},le=M.getInstance(),P=class{constructor(e=["nodecrypto","webcrypto","stream","ie11","purejs"]){this.detector=M.getInstance(),this.fallbackOrder=e;}async execute(e){let n=[];for(let r of this.fallbackOrder)try{let t=await this.detector.createBackendByName(r),s=await e(t);return {success:!0,backend:r,data:s}}catch(t){if(n.push({backend:r,error:t}),r===this.fallbackOrder[this.fallbackOrder.length-1])return {success:false,backend:r,data:null,errors:n}}return {success:false,backend:"",data:null,errors:n}}async hash(e){return this.execute(async n=>n.hash(e))}async hashBinary(e){return this.execute(async n=>n.hashBinary(e))}async getBestBackend(){let e=await this.getAvailableBackends();return e.length===0?"purejs":e[0]}async getAvailableBackends(){let e=[];for(let n of this.fallbackOrder)try{await this.detector.createBackendByName(n),e.push(n);}catch{}return e}getMetrics(){return {}}},be=new P;async function pe(i,e={}){let n=new P;if(e.forceBackend)return (await n.detector.createBackendByName(e.forceBackend)).hash(i);if(e.fallback===false)return (await n.detector.createBackend()).hash(i);let r=await n.hash(i);if(r.success)return e.reportFallback&&r.backend!=="nodecrypto"&&r.backend!=="webcrypto"&&console.info(`MD5 used fallback backend: ${r.backend}`),r.data;let t=r.errors?r.errors.map(s=>`${s.backend}: ${s.error.message}`).join(", "):"All backends failed";throw new Error(`MD5 hash failed after all attempts: ${t}`)}var U=class{constructor(){this.metrics={nodecrypto:{success:0,fail:0},webcrypto:{success:0,fail:0},ie11:{success:0,fail:0},stream:{success:0,fail:0},purejs:{success:0,fail:0}};}recordSuccess(e){this.metrics[e]&&this.metrics[e].success++;}recordFail(e){this.metrics[e]&&this.metrics[e].fail++;}getMetrics(){return this.metrics}getSummary(){return `Total operations: ${Object.values(this.metrics).reduce((n,r)=>n+r.success+r.fail,0)}
2
+ `+Object.entries(this.metrics).map(([,n])=>`${n.success} success, ${n.fail} fail`).join(`
3
+ `)}reset(){Object.keys(this.metrics).forEach(e=>{this.metrics[e]={success:0,fail:0};});}},he=new U;async function W(i,e={}){if(typeof i!="string"||i.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!D.existsSync(i))throw new Error(`File not found: ${i}`);let n;try{n=D.statSync(i);}catch(t){throw new Error(`Failed to access file ${i}: ${t.message}`)}if(!n.isFile())throw new Error(`Path is not a file: ${i}`);let r=D.createReadStream(i,{highWaterMark:e.chunkSize||64*1024});try{return await T(r,{onProgress:e.onProgress,totalSize:n.size})}finally{r.destroy();}}async function T(i,e={}){if(!i||typeof i.on!="function")throw new Error("Invalid readable stream: stream must have event listener support");let n=R(),r=0;return e.onProgress&&i.on("data",t=>{r+=t.length,e.onProgress?.(r);}),i.on("error",t=>{n.destroy(t);}),i.on("end",()=>{n.end();}),new Promise((t,s)=>{n.on("md5",a=>{t(a);}).on("error",a=>{s(a);}),i.pipe(n);})}async function J(i,e={}){return (await W(i,e)).digest}async function Y(i,e={}){return (await T(i,e)).digest}async function Q(i,e,n={}){return (await W(i,n)).digest.toLowerCase()===e.toLowerCase()}function V(i){if(typeof i!="string"||i.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!D.existsSync(i))throw new Error(`File not found: ${i}`);let e;try{e=D.statSync(i);}catch(r){throw new Error(`Failed to access file ${i}: ${r.message}`)}if(!e.isFile())throw new Error(`Path is not a file: ${i}`);let n;try{n=D.readFileSync(i);}catch(r){throw new Error(`Failed to read file ${i}: ${r.message}`)}return q(n)}function X(i,e){let n=0;return r=>{if(i>0){let t=Math.min(100,r/i*100);Math.floor(t)!==Math.floor(n)&&(e(t),n=t);}}}Object.defineProperty(p,"fromStream",{value:j,writable:false,configurable:false});var H=class{constructor(){this.backend=null;this.backendName=null;}async hash(e){return (await this.getBackend()).hash(e)}async hashBinary(e){return (await this.getBackend()).hashBinary(e)}async getBackendName(){if(!this.backendName){let e=await x();this.backendName=F(e);}return this.backendName}static async getAvailableBackends(){return await x()}async useBackend(e){this.backend=await this.createBackendByName(e),this.backendName=e;}async createBackendByName(e){switch(e){case "nodecrypto":return new w;case "webcrypto":return new g;case "ie11":return new B;case "stream":return new A;default:return {hash:n=>l(n),hashBinary:async n=>l(n instanceof Uint8Array?new TextDecoder().decode(n):new TextDecoder().decode(new Uint8Array(n))),update:()=>{},digest:()=>"",reset:()=>{},name:"purejs",version:"0.1.0"}}}async getBackend(){if(this.backend)return this.backend;let e=await x(),n=F(e);return this.backend=await this.createBackendByName(n),this.backendName=n,this.backend}};function Ar(i){return l(i)}var ye=new H;async function xr(i){return ye.hash(i)}export{M as BackendDetector,P as FallbackManager,B as IE11Backend,p as MD5Stream,U as MetricsCollector,w as NodeCryptoBackend,k as PureJSBackend,g as WebCryptoBackend,R as createMD5Stream,X as createProgressTracker,le as detector,be as fallbackManager,j as fromStream,x as getAllAvailableBackends,F as getBestAvailableBackend,W as hashFile,J as hashFileDigest,T as hashFileStream,Y as hashFileStreamDigest,V as hashFileSync,Ar as md5,ye as md5Adapter,xr as md5Async,l as md5Core,l as md5Original,he as metrics,E as pipeThroughMD5,pe as robustHash,Q as verifyFile};
package/dist/md5.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var C="0123456789abcdef".split(""),h=C;function v(m){let u="";for(let o=0;o<4;o++)u+=h[m>>o*8+4&15]+h[m>>o*8&15];return u}function j(m){let u=m.length,o=new Array(u);for(let r=0;r<u;r++)o[r]=v(m[r]);return o.join("")}var s=j;function w(m,u){return m+u&4294967295}var f=w;function _(m,u,o,r,n){let e=n||f;return u=e(e(u,m),e(o,r)),u}function q(m,u,o,r){var e=(r||f)(m<<u|m>>>32-u,o);return e}function l(m,u,o,r,n,e,t){return u=_(m,u,r,e,t),q(u,n,o,t)}function g(m,u,o,r,n,e,t,b){return l(o&r|~o&n,u,o,e,t,b,m)}function a(m,u,o,r,n,e,t,b){return l(o&n|r&~n,u,o,e,t,b,m)}function A(m,u,o,r,n,e,t,b){return l(o^r^n,u,o,e,t,b,m)}function x(m,u,o,r,n,e,t,b){return l(r^(o|~n),u,o,e,t,b,m)}function z(m,u,o){typeof o>"u"&&(o=f);let r=m[0],n=m[1],e=m[2],t=m[3],b=g.bind(null,o);r=b(r,n,e,t,u[0],7,-680876936),t=b(t,r,n,e,u[1],12,-389564586),e=b(e,t,r,n,u[2],17,606105819),n=b(n,e,t,r,u[3],22,-1044525330),r=b(r,n,e,t,u[4],7,-176418897),t=b(t,r,n,e,u[5],12,1200080426),e=b(e,t,r,n,u[6],17,-1473231341),n=b(n,e,t,r,u[7],22,-45705983),r=b(r,n,e,t,u[8],7,1770035416),t=b(t,r,n,e,u[9],12,-1958414417),e=b(e,t,r,n,u[10],17,-42063),n=b(n,e,t,r,u[11],22,-1990404162),r=b(r,n,e,t,u[12],7,1804603682),t=b(t,r,n,e,u[13],12,-40341101),e=b(e,t,r,n,u[14],17,-1502002290),n=b(n,e,t,r,u[15],22,1236535329);let i=a.bind(null,o);r=i(r,n,e,t,u[1],5,-165796510),t=i(t,r,n,e,u[6],9,-1069501632),e=i(e,t,r,n,u[11],14,643717713),n=i(n,e,t,r,u[0],20,-373897302),r=i(r,n,e,t,u[5],5,-701558691),t=i(t,r,n,e,u[10],9,38016083),e=i(e,t,r,n,u[15],14,-660478335),n=i(n,e,t,r,u[4],20,-405537848),r=i(r,n,e,t,u[9],5,568446438),t=i(t,r,n,e,u[14],9,-1019803690),e=i(e,t,r,n,u[3],14,-187363961),n=i(n,e,t,r,u[8],20,1163531501),r=i(r,n,e,t,u[13],5,-1444681467),t=i(t,r,n,e,u[2],9,-51403784),e=i(e,t,r,n,u[7],14,1735328473),n=i(n,e,t,r,u[12],20,-1926607734);let d=A.bind(null,o);r=d(r,n,e,t,u[5],4,-378558),t=d(t,r,n,e,u[8],11,-2022574463),e=d(e,t,r,n,u[11],16,1839030562),n=d(n,e,t,r,u[14],23,-35309556),r=d(r,n,e,t,u[1],4,-1530992060),t=d(t,r,n,e,u[4],11,1272893353),e=d(e,t,r,n,u[7],16,-155497632),n=d(n,e,t,r,u[10],23,-1094730640),r=d(r,n,e,t,u[13],4,681279174),t=d(t,r,n,e,u[0],11,-358537222),e=d(e,t,r,n,u[3],16,-722521979),n=d(n,e,t,r,u[6],23,76029189),r=d(r,n,e,t,u[9],4,-640364487),t=d(t,r,n,e,u[12],11,-421815835),e=d(e,t,r,n,u[15],16,530742520),n=d(n,e,t,r,u[2],23,-995338651);let c=x.bind(null,o);r=c(r,n,e,t,u[0],6,-198630844),t=c(t,r,n,e,u[7],10,1126891415),e=c(e,t,r,n,u[14],15,-1416354905),n=c(n,e,t,r,u[5],21,-57434055),r=c(r,n,e,t,u[12],6,1700485571),t=c(t,r,n,e,u[3],10,-1894986606),e=c(e,t,r,n,u[10],15,-1051523),n=c(n,e,t,r,u[1],21,-2054922799),r=c(r,n,e,t,u[8],6,1873313359),t=c(t,r,n,e,u[15],10,-30611744),e=c(e,t,r,n,u[6],15,-1560198380),n=c(n,e,t,r,u[13],21,1309151649),r=c(r,n,e,t,u[4],6,-145523070),t=c(t,r,n,e,u[11],10,-1120210379),e=c(e,t,r,n,u[2],15,718787259),n=c(n,e,t,r,u[9],21,-343485551),m[0]=o(r,m[0]),m[1]=o(n,m[1]),m[2]=o(e,m[2]),m[3]=o(t,m[3]);}var p=z;function B(m){let u=[];for(let o=0;o<64;o+=4)u[o>>2]=(m.charCodeAt(o)||0)+((m.charCodeAt(o+1)||0)<<8)+((m.charCodeAt(o+2)||0)<<16)+((m.charCodeAt(o+3)||0)<<24);return u}var F=B;function D(m,u){let o=m.length,r=[1732584193,-271733879,-1732584194,271733878],n;for(n=64;n<=o;n+=64)p(r,F(m.substring(n-64,n)),u);m=m.substring(n-64);var e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=m.length;for(n=0;n<t;n++)e[n>>2]|=(m.charCodeAt(n)&255)<<(n%4<<3);if(e[n>>2]|=128<<(n%4<<3),n>55)for(p(r,e,u),n=16;n--;)e[n]=0;return e[14]=o*8,p(r,e,u),r}var y=D;function V(m){return s(y(m,f))}exports.md5=V;
package/dist/md5.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Pure MD5 - Minimal entry point for basic MD5 hashing
3
+ * Only includes the md5() function with zero dependencies
4
+ * Perfect for tree-shaking - will only bundle what's needed
5
+ */
6
+ /**
7
+ * Compute MD5 hash of a string
8
+ * @param data - Input string to hash
9
+ * @returns MD5 hash as hex string (32 characters)
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { md5 } from 'pure-md5/md5';
14
+ *
15
+ * md5('hello'); // "5d41402abc4b2a76b9719d911017c592"
16
+ * ```
17
+ */
18
+ declare function md5(data: string): string;
19
+
20
+ export { md5 };
package/dist/md5.js ADDED
@@ -0,0 +1 @@
1
+ var C="0123456789abcdef".split(""),h=C;function v(m){let u="";for(let o=0;o<4;o++)u+=h[m>>o*8+4&15]+h[m>>o*8&15];return u}function j(m){let u=m.length,o=new Array(u);for(let r=0;r<u;r++)o[r]=v(m[r]);return o.join("")}var s=j;function w(m,u){return m+u&4294967295}var f=w;function _(m,u,o,r,n){let e=n||f;return u=e(e(u,m),e(o,r)),u}function q(m,u,o,r){var e=(r||f)(m<<u|m>>>32-u,o);return e}function l(m,u,o,r,n,e,t){return u=_(m,u,r,e,t),q(u,n,o,t)}function g(m,u,o,r,n,e,t,b){return l(o&r|~o&n,u,o,e,t,b,m)}function a(m,u,o,r,n,e,t,b){return l(o&n|r&~n,u,o,e,t,b,m)}function A(m,u,o,r,n,e,t,b){return l(o^r^n,u,o,e,t,b,m)}function x(m,u,o,r,n,e,t,b){return l(r^(o|~n),u,o,e,t,b,m)}function z(m,u,o){typeof o>"u"&&(o=f);let r=m[0],n=m[1],e=m[2],t=m[3],b=g.bind(null,o);r=b(r,n,e,t,u[0],7,-680876936),t=b(t,r,n,e,u[1],12,-389564586),e=b(e,t,r,n,u[2],17,606105819),n=b(n,e,t,r,u[3],22,-1044525330),r=b(r,n,e,t,u[4],7,-176418897),t=b(t,r,n,e,u[5],12,1200080426),e=b(e,t,r,n,u[6],17,-1473231341),n=b(n,e,t,r,u[7],22,-45705983),r=b(r,n,e,t,u[8],7,1770035416),t=b(t,r,n,e,u[9],12,-1958414417),e=b(e,t,r,n,u[10],17,-42063),n=b(n,e,t,r,u[11],22,-1990404162),r=b(r,n,e,t,u[12],7,1804603682),t=b(t,r,n,e,u[13],12,-40341101),e=b(e,t,r,n,u[14],17,-1502002290),n=b(n,e,t,r,u[15],22,1236535329);let i=a.bind(null,o);r=i(r,n,e,t,u[1],5,-165796510),t=i(t,r,n,e,u[6],9,-1069501632),e=i(e,t,r,n,u[11],14,643717713),n=i(n,e,t,r,u[0],20,-373897302),r=i(r,n,e,t,u[5],5,-701558691),t=i(t,r,n,e,u[10],9,38016083),e=i(e,t,r,n,u[15],14,-660478335),n=i(n,e,t,r,u[4],20,-405537848),r=i(r,n,e,t,u[9],5,568446438),t=i(t,r,n,e,u[14],9,-1019803690),e=i(e,t,r,n,u[3],14,-187363961),n=i(n,e,t,r,u[8],20,1163531501),r=i(r,n,e,t,u[13],5,-1444681467),t=i(t,r,n,e,u[2],9,-51403784),e=i(e,t,r,n,u[7],14,1735328473),n=i(n,e,t,r,u[12],20,-1926607734);let d=A.bind(null,o);r=d(r,n,e,t,u[5],4,-378558),t=d(t,r,n,e,u[8],11,-2022574463),e=d(e,t,r,n,u[11],16,1839030562),n=d(n,e,t,r,u[14],23,-35309556),r=d(r,n,e,t,u[1],4,-1530992060),t=d(t,r,n,e,u[4],11,1272893353),e=d(e,t,r,n,u[7],16,-155497632),n=d(n,e,t,r,u[10],23,-1094730640),r=d(r,n,e,t,u[13],4,681279174),t=d(t,r,n,e,u[0],11,-358537222),e=d(e,t,r,n,u[3],16,-722521979),n=d(n,e,t,r,u[6],23,76029189),r=d(r,n,e,t,u[9],4,-640364487),t=d(t,r,n,e,u[12],11,-421815835),e=d(e,t,r,n,u[15],16,530742520),n=d(n,e,t,r,u[2],23,-995338651);let c=x.bind(null,o);r=c(r,n,e,t,u[0],6,-198630844),t=c(t,r,n,e,u[7],10,1126891415),e=c(e,t,r,n,u[14],15,-1416354905),n=c(n,e,t,r,u[5],21,-57434055),r=c(r,n,e,t,u[12],6,1700485571),t=c(t,r,n,e,u[3],10,-1894986606),e=c(e,t,r,n,u[10],15,-1051523),n=c(n,e,t,r,u[1],21,-2054922799),r=c(r,n,e,t,u[8],6,1873313359),t=c(t,r,n,e,u[15],10,-30611744),e=c(e,t,r,n,u[6],15,-1560198380),n=c(n,e,t,r,u[13],21,1309151649),r=c(r,n,e,t,u[4],6,-145523070),t=c(t,r,n,e,u[11],10,-1120210379),e=c(e,t,r,n,u[2],15,718787259),n=c(n,e,t,r,u[9],21,-343485551),m[0]=o(r,m[0]),m[1]=o(n,m[1]),m[2]=o(e,m[2]),m[3]=o(t,m[3]);}var p=z;function B(m){let u=[];for(let o=0;o<64;o+=4)u[o>>2]=(m.charCodeAt(o)||0)+((m.charCodeAt(o+1)||0)<<8)+((m.charCodeAt(o+2)||0)<<16)+((m.charCodeAt(o+3)||0)<<24);return u}var F=B;function D(m,u){let o=m.length,r=[1732584193,-271733879,-1732584194,271733878],n;for(n=64;n<=o;n+=64)p(r,F(m.substring(n-64,n)),u);m=m.substring(n-64);var e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=m.length;for(n=0;n<t;n++)e[n>>2]|=(m.charCodeAt(n)&255)<<(n%4<<3);if(e[n>>2]|=128<<(n%4<<3),n>55)for(p(r,e,u),n=16;n--;)e[n]=0;return e[14]=o*8,p(r,e,u),r}var y=D;function V(m){return s(y(m,f))}export{V as md5};
@@ -1 +1 @@
1
- export{a as MD5Stream,b as createMD5Stream,d as fromStream,c as pipeThroughMD5}from'../chunk-MIU3X4SB.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
1
+ import {Transform}from'stream';function B(i,s){return i+s&4294967295}var l=B;function v(i,s,u,t,r){let e=r||l;return s=e(e(s,i),e(u,t)),s}function w(i,s,u,t){var e=(t||l)(i<<s|i>>>32-s,u);return e}function g(i,s,u,t,r,e,n){return s=v(i,s,t,e,n),w(s,r,u,n)}function D(i,s,u,t,r,e,n,f){return g(u&t|~u&r,s,u,e,n,f,i)}function x(i,s,u,t,r,e,n,f){return g(u&r|t&~r,s,u,e,n,f,i)}function P(i,s,u,t,r,e,n,f){return g(u^t^r,s,u,e,n,f,i)}function S(i,s,u,t,r,e,n,f){return g(t^(u|~r),s,u,e,n,f,i)}function F(i,s,u){typeof u>"u"&&(u=l);let t=i[0],r=i[1],e=i[2],n=i[3],f=D.bind(null,u);t=f(t,r,e,n,s[0],7,-680876936),n=f(n,t,r,e,s[1],12,-389564586),e=f(e,n,t,r,s[2],17,606105819),r=f(r,e,n,t,s[3],22,-1044525330),t=f(t,r,e,n,s[4],7,-176418897),n=f(n,t,r,e,s[5],12,1200080426),e=f(e,n,t,r,s[6],17,-1473231341),r=f(r,e,n,t,s[7],22,-45705983),t=f(t,r,e,n,s[8],7,1770035416),n=f(n,t,r,e,s[9],12,-1958414417),e=f(e,n,t,r,s[10],17,-42063),r=f(r,e,n,t,s[11],22,-1990404162),t=f(t,r,e,n,s[12],7,1804603682),n=f(n,t,r,e,s[13],12,-40341101),e=f(e,n,t,r,s[14],17,-1502002290),r=f(r,e,n,t,s[15],22,1236535329);let o=x.bind(null,u);t=o(t,r,e,n,s[1],5,-165796510),n=o(n,t,r,e,s[6],9,-1069501632),e=o(e,n,t,r,s[11],14,643717713),r=o(r,e,n,t,s[0],20,-373897302),t=o(t,r,e,n,s[5],5,-701558691),n=o(n,t,r,e,s[10],9,38016083),e=o(e,n,t,r,s[15],14,-660478335),r=o(r,e,n,t,s[4],20,-405537848),t=o(t,r,e,n,s[9],5,568446438),n=o(n,t,r,e,s[14],9,-1019803690),e=o(e,n,t,r,s[3],14,-187363961),r=o(r,e,n,t,s[8],20,1163531501),t=o(t,r,e,n,s[13],5,-1444681467),n=o(n,t,r,e,s[2],9,-51403784),e=o(e,n,t,r,s[7],14,1735328473),r=o(r,e,n,t,s[12],20,-1926607734);let a=P.bind(null,u);t=a(t,r,e,n,s[5],4,-378558),n=a(n,t,r,e,s[8],11,-2022574463),e=a(e,n,t,r,s[11],16,1839030562),r=a(r,e,n,t,s[14],23,-35309556),t=a(t,r,e,n,s[1],4,-1530992060),n=a(n,t,r,e,s[4],11,1272893353),e=a(e,n,t,r,s[7],16,-155497632),r=a(r,e,n,t,s[10],23,-1094730640),t=a(t,r,e,n,s[13],4,681279174),n=a(n,t,r,e,s[0],11,-358537222),e=a(e,n,t,r,s[3],16,-722521979),r=a(r,e,n,t,s[6],23,76029189),t=a(t,r,e,n,s[9],4,-640364487),n=a(n,t,r,e,s[12],11,-421815835),e=a(e,n,t,r,s[15],16,530742520),r=a(r,e,n,t,s[2],23,-995338651);let b=S.bind(null,u);t=b(t,r,e,n,s[0],6,-198630844),n=b(n,t,r,e,s[7],10,1126891415),e=b(e,n,t,r,s[14],15,-1416354905),r=b(r,e,n,t,s[5],21,-57434055),t=b(t,r,e,n,s[12],6,1700485571),n=b(n,t,r,e,s[3],10,-1894986606),e=b(e,n,t,r,s[10],15,-1051523),r=b(r,e,n,t,s[1],21,-2054922799),t=b(t,r,e,n,s[8],6,1873313359),n=b(n,t,r,e,s[15],10,-30611744),e=b(e,n,t,r,s[6],15,-1560198380),r=b(r,e,n,t,s[13],21,1309151649),t=b(t,r,e,n,s[4],6,-145523070),n=b(n,t,r,e,s[11],10,-1120210379),e=b(e,n,t,r,s[2],15,718787259),r=b(r,e,n,t,s[9],21,-343485551),i[0]=u(t,i[0]),i[1]=u(r,i[1]),i[2]=u(e,i[2]),i[3]=u(n,i[3]);}var p=F;var R="0123456789abcdef".split(""),M=R;function C(i){let s="";for(let u=0;u<4;u++)s+=M[i>>u*8+4&15]+M[i>>u*8&15];return s}function O(i){let s=i.length,u=new Array(s);for(let t=0;t<s;t++)u[t]=C(i[t]);return u.join("")}var A=O;var y=class i extends Transform{constructor(u){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=u?.add32||l,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(u,t,r){try{let e=u,n=e.length;if(n===0){r();return}if(this.state.bufferLength>0){let a=this.state.bufferLength,b=64-a,c=Math.min(n,b);for(let m=0;m<c;m++)this.buffer[a+m]=e[m];if(this.state.bufferLength+=c,this.state.bufferLength===64&&this._processBufferBlock(),c===n){r();return}let d=n-c;for(let m=0;m<d;m++)e[m]=e[c+m];let h=Buffer.alloc(d);for(let m=0;m<d;m++)h[m]=e[m];e=h;}let f=Math.floor(e.length/64);for(let a=0;a<f;a++){let b=a*64,c=[];for(let d=0;d<16;d++){let h=b+d*4;c[d]=e[h]+(e[h+1]<<8)+(e[h+2]<<16)+(e[h+3]<<24);}p(this.state.state,c,this.add32),this.state.bytesProcessed+=64;}let o=e.length%64;if(o>0){this.buffer.length<o&&(this.buffer=new Uint8Array(o),this.state.buffer=this.buffer);for(let a=0;a<o;a++)this.buffer[a]=e[f*64+a];this.state.bufferLength=o;}r();}catch(e){r(e);}}_processBufferBlock(){let u=this.state.buffer,t=[];for(let r=0;r<16;r++){let e=r*4;t[r]=u[e]+(u[e+1]<<8)+(u[e+2]<<16)+(u[e+3]<<24);}p(this.state.state,t,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(u){try{let{state:t,bufferLength:r,buffer:e}=this.state,n=new Array(16).fill(0);for(let o=0;o<r;o++)n[o>>2]|=(e[o]&255)<<(o%4<<3);if(n[r>>2]|=128<<(r%4<<3),r>55){p(t,n,this.add32);for(let o=0;o<16;o++)n[o]=0;}n[14]=(this.state.bytesProcessed+r)*8,n[15]=0,p(t,n,this.add32);let f=A(t);this.emit("md5",{digest:f,bytesProcessed:this.state.bytesProcessed+r}),u();}catch(t){u(t);}}getCurrentState(){return {state:[...this.state.state],bytesProcessed:this.state.bytesProcessed+this.state.bufferLength}}getBytesProcessed(){return this.state.bytesProcessed+this.state.bufferLength}reset(){this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer},this.buffer=new Uint8Array(this.bufferCapacity),this.state.buffer=this.buffer,this.state.bufferLength=0;}static fromStream(u,t){let r=new i(t),e=L.call(r,u);return {stream:r,result:e}}};function W(i){return new y(i)}async function L(i){return new Promise((s,u)=>{let t=[];i.pipe(this).on("md5",r=>{t.push(r);}).on("error",u).on("finish",()=>{s(t[0]);});})}function X(i,s){let u=new y(s),t=L.call(u,i);return {stream:u,result:t}}export{y as MD5Stream,W as createMD5Stream,X as fromStream,L as pipeThroughMD5};
@@ -1 +1 @@
1
- export{a as MD5ReadableStream,f as consumeWithMD5,b as createMD5ReadableStream,e as hashBlob,d as hashFile,c as hashReadableStream}from'../chunk-BEGGPFEE.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
1
+ function P(i,t){return i+t&4294967295}var m=P;function S(i,t,a,e,n){let s=n||m;return t=s(s(t,i),s(a,e)),t}function w(i,t,a,e){var s=(e||m)(i<<t|i>>>32-t,a);return s}function h(i,t,a,e,n,s,r){return t=S(i,t,e,s,r),w(t,n,a,r)}function y(i,t,a,e,n,s,r,u){return h(a&e|~a&n,t,a,s,r,u,i)}function R(i,t,a,e,n,s,r,u){return h(a&n|e&~n,t,a,s,r,u,i)}function g(i,t,a,e,n,s,r,u){return h(a^e^n,t,a,s,r,u,i)}function D(i,t,a,e,n,s,r,u){return h(e^(a|~n),t,a,s,r,u,i)}function A(i,t,a){typeof a>"u"&&(a=m);let e=i[0],n=i[1],s=i[2],r=i[3],u=y.bind(null,a);e=u(e,n,s,r,t[0],7,-680876936),r=u(r,e,n,s,t[1],12,-389564586),s=u(s,r,e,n,t[2],17,606105819),n=u(n,s,r,e,t[3],22,-1044525330),e=u(e,n,s,r,t[4],7,-176418897),r=u(r,e,n,s,t[5],12,1200080426),s=u(s,r,e,n,t[6],17,-1473231341),n=u(n,s,r,e,t[7],22,-45705983),e=u(e,n,s,r,t[8],7,1770035416),r=u(r,e,n,s,t[9],12,-1958414417),s=u(s,r,e,n,t[10],17,-42063),n=u(n,s,r,e,t[11],22,-1990404162),e=u(e,n,s,r,t[12],7,1804603682),r=u(r,e,n,s,t[13],12,-40341101),s=u(s,r,e,n,t[14],17,-1502002290),n=u(n,s,r,e,t[15],22,1236535329);let o=R.bind(null,a);e=o(e,n,s,r,t[1],5,-165796510),r=o(r,e,n,s,t[6],9,-1069501632),s=o(s,r,e,n,t[11],14,643717713),n=o(n,s,r,e,t[0],20,-373897302),e=o(e,n,s,r,t[5],5,-701558691),r=o(r,e,n,s,t[10],9,38016083),s=o(s,r,e,n,t[15],14,-660478335),n=o(n,s,r,e,t[4],20,-405537848),e=o(e,n,s,r,t[9],5,568446438),r=o(r,e,n,s,t[14],9,-1019803690),s=o(s,r,e,n,t[3],14,-187363961),n=o(n,s,r,e,t[8],20,1163531501),e=o(e,n,s,r,t[13],5,-1444681467),r=o(r,e,n,s,t[2],9,-51403784),s=o(s,r,e,n,t[7],14,1735328473),n=o(n,s,r,e,t[12],20,-1926607734);let l=g.bind(null,a);e=l(e,n,s,r,t[5],4,-378558),r=l(r,e,n,s,t[8],11,-2022574463),s=l(s,r,e,n,t[11],16,1839030562),n=l(n,s,r,e,t[14],23,-35309556),e=l(e,n,s,r,t[1],4,-1530992060),r=l(r,e,n,s,t[4],11,1272893353),s=l(s,r,e,n,t[7],16,-155497632),n=l(n,s,r,e,t[10],23,-1094730640),e=l(e,n,s,r,t[13],4,681279174),r=l(r,e,n,s,t[0],11,-358537222),s=l(s,r,e,n,t[3],16,-722521979),n=l(n,s,r,e,t[6],23,76029189),e=l(e,n,s,r,t[9],4,-640364487),r=l(r,e,n,s,t[12],11,-421815835),s=l(s,r,e,n,t[15],16,530742520),n=l(n,s,r,e,t[2],23,-995338651);let b=D.bind(null,a);e=b(e,n,s,r,t[0],6,-198630844),r=b(r,e,n,s,t[7],10,1126891415),s=b(s,r,e,n,t[14],15,-1416354905),n=b(n,s,r,e,t[5],21,-57434055),e=b(e,n,s,r,t[12],6,1700485571),r=b(r,e,n,s,t[3],10,-1894986606),s=b(s,r,e,n,t[10],15,-1051523),n=b(n,s,r,e,t[1],21,-2054922799),e=b(e,n,s,r,t[8],6,1873313359),r=b(r,e,n,s,t[15],10,-30611744),s=b(s,r,e,n,t[6],15,-1560198380),n=b(n,s,r,e,t[13],21,1309151649),e=b(e,n,s,r,t[4],6,-145523070),r=b(r,e,n,s,t[11],10,-1120210379),s=b(s,r,e,n,t[2],15,718787259),n=b(n,s,r,e,t[9],21,-343485551),i[0]=a(e,i[0]),i[1]=a(n,i[1]),i[2]=a(s,i[2]),i[3]=a(r,i[3]);}var c=A;var v="0123456789abcdef".split(""),p=v;function B(i){let t="";for(let a=0;a<4;a++)t+=p[i>>a*8+4&15]+p[i>>a*8&15];return t}function x(i){let t=i.length,a=new Array(t);for(let e=0;e<t;e++)a[e]=B(i[e]);return a.join("")}var M=x;var F=[1732584193,-271733879,-1732584194,271733878],d=class i{constructor(t,a={}){this.result=null;this.resultResolver=null;this.consumed=false;this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.sourceStream=t,this.state={state:[...F],bytesProcessed:0,bufferLength:0,buffer:this.buffer},this.add32=a.add32||m,this.resultPromise=new Promise(e=>{this.resultResolver=e;});}getReader(){if(this.consumed)throw new Error("Cannot get reader from MD5ReadableStream: stream has already been consumed");this.consumed=true;let{readable:t,writable:a}=new TransformStream({transform:async(e,n)=>{await this.processChunk(e),n.enqueue(e);},flush:async e=>{this.finalize(),this.resultResolver&&this.resultResolver(this.result);}});return this.sourceStream.pipeTo(a).catch(e=>{console.error("Error piping stream:",e),this.resultResolver&&this.resultResolver({digest:"",bytesProcessed:this.state.bytesProcessed});}),t.getReader()}async processChunk(t){let a;t instanceof Blob?a=new Uint8Array(await t.arrayBuffer()):t instanceof ArrayBuffer?a=new Uint8Array(t):a=t;let e=a.length;if(e===0)return;if(this.state.bufferLength>0){let r=this.state.bufferLength,u=64-r,o=Math.min(e,u);for(let f=0;f<o;f++)this.buffer[r+f]=a[f];if(this.state.bufferLength+=o,this.state.bufferLength===64&&this._processBufferBlock(),o===e)return;let l=e-o,b=new Uint8Array(l);for(let f=0;f<l;f++)b[f]=a[o+f];a=b;}let n=Math.floor(a.length/64);for(let r=0;r<n;r++){let u=r*64,o=[];for(let l=0;l<16;l++){let b=u+l*4;o[l]=a[b]+(a[b+1]<<8)+(a[b+2]<<16)+(a[b+3]<<24);}c(this.state.state,o,this.add32),this.state.bytesProcessed+=64;}let s=a.length%64;if(s>0){this.buffer.length<s&&(this.buffer=new Uint8Array(s),this.state.buffer=this.buffer);for(let r=0;r<s;r++)this.buffer[r]=a[n+r];this.state.bufferLength=s;}}_processBufferBlock(){let t=this.state.buffer,a=[];for(let e=0;e<16;e++){let n=e*4;a[e]=t[n]+(t[n+1]<<8)+(t[n+2]<<16)+(t[n+3]<<24);}c(this.state.state,a,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}finalize(){let{state:t,bufferLength:a,buffer:e}=this.state,n=new Array(16).fill(0);for(let r=0;r<a;r++)n[r>>2]|=(e[r]&255)<<(r%4<<3);if(n[a>>2]|=128<<(a%4<<3),a>55){c(t,n,this.add32);for(let r=0;r<16;r++)n[r]=0;}n[14]=(this.state.bytesProcessed+a)*8,n[15]=0,c(t,n,this.add32);let s=M(t);this.result={digest:s,bytesProcessed:this.state.bytesProcessed+a};}getResult(){return this.resultPromise}getCurrentState(){return {state:[...this.state.state],bytesProcessed:this.state.bytesProcessed+this.state.bufferLength}}getBytesProcessed(){return this.state.bytesProcessed+this.state.bufferLength}static hash(t,a){let e=new i(t,a),n=e.getReader();return new Promise((s,r)=>{let u=0;n.read().then(function o({done:l,value:b}){if(l){s(e.getResult());return}u+=b.length,n.read().then(o);}).catch(r);})}static hashFile(t,a){let e=t.stream();return i.hash(e,a)}static hashBlob(t,a){return new Promise((e,n)=>{let s=new FileReader;s.onload=r=>{try{let u=r.target?.result,o=new ReadableStream({start(l){l.enqueue(new Uint8Array(u)),l.close();}});e(i.hash(o,a));}catch(u){n(u);}},s.onerror=()=>n(s.error),s.readAsArrayBuffer(t);})}};function H(i,t){return new d(i,t)}async function I(i,t){let a=i.getReader(),e=new d(i,t),n=0;for(;;){let{done:s,value:r}=await a.read();if(s)break;r&&(n+=r.length);}return e.getResult()}async function J(i,t){return d.hashFile(i,t)}async function K(i,t){return d.hashBlob(i,t)}async function N(i,t){let a=i.getReader(),e=new d(i,t),n=0;for(;;){let{done:s,value:r}=await a.read();if(s)break;r&&(n+=r.length);}return e.getResult()}export{d as MD5ReadableStream,N as consumeWithMD5,H as createMD5ReadableStream,K as hashBlob,J as hashFile,I as hashReadableStream};
@@ -1 +1,3 @@
1
- export{i as BACKEND_PRIORITY,k as BackendDetector,m as FallbackManager,p as MetricsCollector,b as RuntimeEnvironment,g as checkBackendAvailability,c as detectEnvironment,l as detector,n as fallbackManager,h as getAllAvailableBackends,j as getBestAvailableBackend,e as isBrowser,d as isNode,f as isWebWorker,q as metrics,o as robustHash}from'../chunk-4F2Y3CRO.js';import'../chunk-QB6MF5LD.js';import'../chunk-XPYPJSJE.js';import'../chunk-43QQAXLT.js';import'../chunk-Y2ZKN4NS.js';import'../chunk-Z4JB6DTM.js';import'../chunk-MIU3X4SB.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
1
+ import {Transform}from'stream';var C=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(e,s)=>(typeof require<"u"?require:e)[s]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var N="0123456789abcdef".split(""),U=N;function F(a){let e="";for(let s=0;s<4;s++)e+=U[a>>s*8+4&15]+U[a>>s*8&15];return e}function L(a){let e=a.length,s=new Array(e);for(let r=0;r<e;r++)s[r]=F(a[r]);return s.join("")}var v=L;function I(a,e){return a+e&4294967295}var m=I;function H(a,e,s,r,t){let n=t||m;return e=n(n(e,a),n(s,r)),e}function _(a,e,s,r){var n=(r||m)(a<<e|a>>>32-e,s);return n}function x(a,e,s,r,t,n,i){return e=H(a,e,r,n,i),_(e,t,s,i)}function W(a,e,s,r,t,n,i,c){return x(s&r|~s&t,e,s,n,i,c,a)}function R(a,e,s,r,t,n,i,c){return x(s&t|r&~t,e,s,n,i,c,a)}function T(a,e,s,r,t,n,i,c){return x(s^r^t,e,s,n,i,c,a)}function E(a,e,s,r,t,n,i,c){return x(r^(s|~t),e,s,n,i,c,a)}function G(a,e,s){typeof s>"u"&&(s=m);let r=a[0],t=a[1],n=a[2],i=a[3],c=W.bind(null,s);r=c(r,t,n,i,e[0],7,-680876936),i=c(i,r,t,n,e[1],12,-389564586),n=c(n,i,r,t,e[2],17,606105819),t=c(t,n,i,r,e[3],22,-1044525330),r=c(r,t,n,i,e[4],7,-176418897),i=c(i,r,t,n,e[5],12,1200080426),n=c(n,i,r,t,e[6],17,-1473231341),t=c(t,n,i,r,e[7],22,-45705983),r=c(r,t,n,i,e[8],7,1770035416),i=c(i,r,t,n,e[9],12,-1958414417),n=c(n,i,r,t,e[10],17,-42063),t=c(t,n,i,r,e[11],22,-1990404162),r=c(r,t,n,i,e[12],7,1804603682),i=c(i,r,t,n,e[13],12,-40341101),n=c(n,i,r,t,e[14],17,-1502002290),t=c(t,n,i,r,e[15],22,1236535329);let o=R.bind(null,s);r=o(r,t,n,i,e[1],5,-165796510),i=o(i,r,t,n,e[6],9,-1069501632),n=o(n,i,r,t,e[11],14,643717713),t=o(t,n,i,r,e[0],20,-373897302),r=o(r,t,n,i,e[5],5,-701558691),i=o(i,r,t,n,e[10],9,38016083),n=o(n,i,r,t,e[15],14,-660478335),t=o(t,n,i,r,e[4],20,-405537848),r=o(r,t,n,i,e[9],5,568446438),i=o(i,r,t,n,e[14],9,-1019803690),n=o(n,i,r,t,e[3],14,-187363961),t=o(t,n,i,r,e[8],20,1163531501),r=o(r,t,n,i,e[13],5,-1444681467),i=o(i,r,t,n,e[2],9,-51403784),n=o(n,i,r,t,e[7],14,1735328473),t=o(t,n,i,r,e[12],20,-1926607734);let u=T.bind(null,s);r=u(r,t,n,i,e[5],4,-378558),i=u(i,r,t,n,e[8],11,-2022574463),n=u(n,i,r,t,e[11],16,1839030562),t=u(t,n,i,r,e[14],23,-35309556),r=u(r,t,n,i,e[1],4,-1530992060),i=u(i,r,t,n,e[4],11,1272893353),n=u(n,i,r,t,e[7],16,-155497632),t=u(t,n,i,r,e[10],23,-1094730640),r=u(r,t,n,i,e[13],4,681279174),i=u(i,r,t,n,e[0],11,-358537222),n=u(n,i,r,t,e[3],16,-722521979),t=u(t,n,i,r,e[6],23,76029189),r=u(r,t,n,i,e[9],4,-640364487),i=u(i,r,t,n,e[12],11,-421815835),n=u(n,i,r,t,e[15],16,530742520),t=u(t,n,i,r,e[2],23,-995338651);let f=E.bind(null,s);r=f(r,t,n,i,e[0],6,-198630844),i=f(i,r,t,n,e[7],10,1126891415),n=f(n,i,r,t,e[14],15,-1416354905),t=f(t,n,i,r,e[5],21,-57434055),r=f(r,t,n,i,e[12],6,1700485571),i=f(i,r,t,n,e[3],10,-1894986606),n=f(n,i,r,t,e[10],15,-1051523),t=f(t,n,i,r,e[1],21,-2054922799),r=f(r,t,n,i,e[8],6,1873313359),i=f(i,r,t,n,e[15],10,-30611744),n=f(n,i,r,t,e[6],15,-1560198380),t=f(t,n,i,r,e[13],21,1309151649),r=f(r,t,n,i,e[4],6,-145523070),i=f(i,r,t,n,e[11],10,-1120210379),n=f(n,i,r,t,e[2],15,718787259),t=f(t,n,i,r,e[9],21,-343485551),a[0]=s(r,a[0]),a[1]=s(t,a[1]),a[2]=s(n,a[2]),a[3]=s(i,a[3]);}var l=G;function $(a){let e=[];for(let s=0;s<64;s+=4)e[s>>2]=(a.charCodeAt(s)||0)+((a.charCodeAt(s+1)||0)<<8)+((a.charCodeAt(s+2)||0)<<16)+((a.charCodeAt(s+3)||0)<<24);return e}var O=$;function K(a,e){let s=a.length,r=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=s;t+=64)l(r,O(a.substring(t-64,t)),e);a=a.substring(t-64);var n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i=a.length;for(t=0;t<i;t++)n[t>>2]|=(a.charCodeAt(t)&255)<<(t%4<<3);if(n[t>>2]|=128<<(t%4<<3),t>55)for(l(r,n,e),t=16;t--;)n[t]=0;return n[14]=s*8,l(r,n,e),r}var j=K;function y(a){return v(j(a,m))}var g=class{constructor(){this.name="webcrypto";this.version="1.0.0";}static isAvailable(){return typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.subtle.digest=="function"}async hash(e){return y(e)}async hashBinary(e){let s=e instanceof ArrayBuffer?new TextDecoder().decode(e):new TextDecoder().decode(e);return y(s)}update(e){throw new Error("Web Crypto API does not support streaming updates")}digest(e){throw new Error("Web Crypto API does not support streaming")}reset(){}};var w=class{constructor(){this.name="nodecrypto";this.version="1.0.0";}static isAvailable(){try{return typeof C("crypto").createHash=="function"}catch{return false}}hash(e){return C("crypto").createHash("md5").update(e).digest("hex")}async hashBinary(e){let s=C("crypto"),r=e instanceof Uint8Array?e:new Uint8Array(e);return s.createHash("md5").update(r).digest("hex")}update(e){}digest(e){throw new Error("Node crypto streaming not implemented")}reset(){}};var A=class{constructor(){this.name="ie11";this.version="1.0.0";}static isAvailable(){if(typeof window>"u")return false;let e=window;return typeof e.msCrypto<"u"&&typeof e.msCrypto.subtle<"u"&&typeof e.msCrypto.subtle.digest=="function"}async hash(e){let r=new TextEncoder().encode(e);return await this.hashBinary(r)}async hashBinary(e){let s=window,r=e instanceof Uint8Array?e.buffer:e,t=await s.msCrypto.subtle.digest("MD5",r);return this.bufferToHex(t)}bufferToHex(e){return Array.from(new Uint8Array(e)).map(s=>s.toString(16).padStart(2,"0")).join("")}update(e){throw new Error("msCrypto does not support streaming updates")}digest(e){throw new Error("msCrypto does not support streaming")}reset(){}};var P=class{constructor(){this.name="purejs";this.version="0.1.0";this.state={data:"",finished:false};}hash(e){return y(e)}async hashBinary(e){let s=e instanceof ArrayBuffer?new TextDecoder().decode(e):new TextDecoder().decode(e);return y(s)}update(e){this.state.finished&&(this.state={data:"",finished:false}),e instanceof ArrayBuffer?this.state.data+=new TextDecoder().decode(e):e instanceof Uint8Array?this.state.data+=new TextDecoder().decode(e):this.state.data+=e;}digest(e){let s=y(this.state.data);return this.state.finished=true,e==="buffer"?this.hexToBuffer(s):s}reset(){this.state={data:"",finished:false};}static isAvailable(){return true}hexToBuffer(e){let s=[];for(let r=0;r<e.length;r+=2)s.push(parseInt(e.substring(r,r+2),16));return new Uint8Array(s)}};var B=class a extends Transform{constructor(s){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=s?.add32||m,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(s,r,t){try{let n=s,i=n.length;if(i===0){t();return}if(this.state.bufferLength>0){let u=this.state.bufferLength,f=64-u,b=Math.min(i,f);for(let d=0;d<b;d++)this.buffer[u+d]=n[d];if(this.state.bufferLength+=b,this.state.bufferLength===64&&this._processBufferBlock(),b===i){t();return}let p=i-b;for(let d=0;d<p;d++)n[d]=n[b+d];let h=Buffer.alloc(p);for(let d=0;d<p;d++)h[d]=n[d];n=h;}let c=Math.floor(n.length/64);for(let u=0;u<c;u++){let f=u*64,b=[];for(let p=0;p<16;p++){let h=f+p*4;b[p]=n[h]+(n[h+1]<<8)+(n[h+2]<<16)+(n[h+3]<<24);}l(this.state.state,b,this.add32),this.state.bytesProcessed+=64;}let o=n.length%64;if(o>0){this.buffer.length<o&&(this.buffer=new Uint8Array(o),this.state.buffer=this.buffer);for(let u=0;u<o;u++)this.buffer[u]=n[c*64+u];this.state.bufferLength=o;}t();}catch(n){t(n);}}_processBufferBlock(){let s=this.state.buffer,r=[];for(let t=0;t<16;t++){let n=t*4;r[t]=s[n]+(s[n+1]<<8)+(s[n+2]<<16)+(s[n+3]<<24);}l(this.state.state,r,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(s){try{let{state:r,bufferLength:t,buffer:n}=this.state,i=new Array(16).fill(0);for(let o=0;o<t;o++)i[o>>2]|=(n[o]&255)<<(o%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55){l(r,i,this.add32);for(let o=0;o<16;o++)i[o]=0;}i[14]=(this.state.bytesProcessed+t)*8,i[15]=0,l(r,i,this.add32);let c=v(r);this.emit("md5",{digest:c,bytesProcessed:this.state.bytesProcessed+t}),s();}catch(r){s(r);}}getCurrentState(){return {state:[...this.state.state],bytesProcessed:this.state.bytesProcessed+this.state.bufferLength}}getBytesProcessed(){return this.state.bytesProcessed+this.state.bufferLength}reset(){this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer},this.buffer=new Uint8Array(this.bufferCapacity),this.state.buffer=this.buffer,this.state.bufferLength=0;}static fromStream(s,r){let t=new a(r),n=z.call(t,s);return {stream:t,result:n}}};async function z(a){return new Promise((e,s)=>{let r=[];a.pipe(this).on("md5",t=>{r.push(t);}).on("error",s).on("finish",()=>{e(r[0]);});})}var D=class{constructor(){this.name="stream";this.version="0.1.0";this.state=null;}initNodeStream(e){this.state={stream:e,type:"node"};}initWhatWGStream(e){this.state={stream:e,type:"whatwg"};}async hash(e){let s=new B;return (await new Promise((t,n)=>{s.on("md5",i=>t(i)).on("error",n).end(e);})).digest}async hashBinary(e){let s=new B,r;return e instanceof Uint8Array?r=Buffer.from(e):e instanceof ArrayBuffer?r=Buffer.from(new Uint8Array(e)):r=Buffer.from(e),(await new Promise((n,i)=>{s.on("md5",c=>n(c)).on("error",i).end(r);})).digest}update(e){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let s=this.state.stream,r;typeof e=="string"||e instanceof Uint8Array?r=Buffer.from(e):e instanceof ArrayBuffer?r=Buffer.from(new Uint8Array(e)):r=Buffer.from(e),s.write(r);}}digest(e){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let s=this.state.stream;return s.end(),new Promise((r,t)=>{s.on("md5",n=>{if(e==="buffer"){let i=n.digest,c=[];for(let o=0;o<i.length;o+=2)c.push(parseInt(i.substring(o,o+2),16));r(Buffer.from(c));}else r(n.digest);}).on("error",t);})}else return this.state.stream.getResult().then(r=>r.digest)}reset(){this.state&&this.state.type==="node"&&this.state.stream.reset();}static isAvailable(){return true}};var J=(t=>(t.BROWSER="browser",t.NODE="node",t.WEBWORKER="webworker",t.UNKNOWN="unknown",t))(J||{});function Ne(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof importScripts<"u"?"webworker":typeof window<"u"&&window.document?"browser":"unknown"}function Fe(){return typeof process<"u"&&process.versions!==void 0&&"node"in process.versions}function Le(){return typeof window<"u"&&typeof document<"u"}function Ie(){return typeof importScripts<"u"}async function Y(a){switch(a){case "webcrypto":let e=g.isAvailable();return {backend:"webcrypto",available:e,reason:e?void 0:"Web Crypto API not available"};case "nodecrypto":let s=w.isAvailable();return {backend:"nodecrypto",available:s,reason:s?void 0:"Node.js crypto not available"};case "ie11":let r=A.isAvailable();return {backend:"ie11",available:r,reason:r?void 0:"IE11 msCrypto not available"};case "purejs":return {backend:"purejs",available:true,reason:"Always available"};case "stream":let t=typeof process<"u"&&process.versions&&"node"in process.versions,n=typeof window<"u";return {backend:"stream",available:t||n,reason:t||n?void 0:"Streams not available"};default:return {backend:a||"unknown",available:false,reason:"Unknown backend"}}}async function Q(){let a=["webcrypto","nodecrypto","ie11","purejs","stream"],e=[];for(let s of a){let{available:r}=await Y(s);r&&e.push(s);}return e}var V=[{name:"nodecrypto",priority:1,description:"Node.js native crypto (fastest)"},{name:"webcrypto",priority:2,description:"Web Crypto API (fast, hardware accelerated)"},{name:"ie11",priority:3,description:"IE11 msCrypto (legacy)"},{name:"stream",priority:4,description:"Streaming backend (for large files and memory efficiency)"},{name:"purejs",priority:5,description:"Pure JavaScript (always available, slower)"}];function X(a){let e=[...V].sort((s,r)=>s.priority-r.priority);for(let{name:s}of e)if(a.includes(s))return s;return "purejs"}var M=class a{constructor(){}static getInstance(){return a.instance||(a.instance=new a),a.instance}async createBackendByName(e){switch(e){case "nodecrypto":return new w;case "webcrypto":return new g;case "ie11":return new A;case "stream":return new D;default:return new P}}async createBackend(e){let s=e||X(await Q());return this.createBackendByName(s)}},He=M.getInstance(),S=class{constructor(e=["nodecrypto","webcrypto","stream","ie11","purejs"]){this.detector=M.getInstance(),this.fallbackOrder=e;}async execute(e){let s=[];for(let r of this.fallbackOrder)try{let t=await this.detector.createBackendByName(r),n=await e(t);return {success:!0,backend:r,data:n}}catch(t){if(s.push({backend:r,error:t}),r===this.fallbackOrder[this.fallbackOrder.length-1])return {success:false,backend:r,data:null,errors:s}}return {success:false,backend:"",data:null,errors:s}}async hash(e){return this.execute(async s=>s.hash(e))}async hashBinary(e){return this.execute(async s=>s.hashBinary(e))}async getBestBackend(){let e=await this.getAvailableBackends();return e.length===0?"purejs":e[0]}async getAvailableBackends(){let e=[];for(let s of this.fallbackOrder)try{await this.detector.createBackendByName(s),e.push(s);}catch{}return e}getMetrics(){return {}}},_e=new S;async function Ge(a,e={}){let s=new S;if(e.forceBackend)return (await s.detector.createBackendByName(e.forceBackend)).hash(a);if(e.fallback===false)return (await s.detector.createBackend()).hash(a);let r=await s.hash(a);if(r.success)return e.reportFallback&&r.backend!=="nodecrypto"&&r.backend!=="webcrypto"&&console.info(`MD5 used fallback backend: ${r.backend}`),r.data;let t=r.errors?r.errors.map(n=>`${n.backend}: ${n.error.message}`).join(", "):"All backends failed";throw new Error(`MD5 hash failed after all attempts: ${t}`)}var k=class{constructor(){this.metrics={nodecrypto:{success:0,fail:0},webcrypto:{success:0,fail:0},ie11:{success:0,fail:0},stream:{success:0,fail:0},purejs:{success:0,fail:0}};}recordSuccess(e){this.metrics[e]&&this.metrics[e].success++;}recordFail(e){this.metrics[e]&&this.metrics[e].fail++;}getMetrics(){return this.metrics}getSummary(){return `Total operations: ${Object.values(this.metrics).reduce((s,r)=>s+r.success+r.fail,0)}
2
+ `+Object.entries(this.metrics).map(([,s])=>`${s.success} success, ${s.fail} fail`).join(`
3
+ `)}reset(){Object.keys(this.metrics).forEach(e=>{this.metrics[e]={success:0,fail:0};});}},$e=new k;export{V as BACKEND_PRIORITY,M as BackendDetector,S as FallbackManager,k as MetricsCollector,J as RuntimeEnvironment,Y as checkBackendAvailability,Ne as detectEnvironment,He as detector,_e as fallbackManager,Q as getAllAvailableBackends,X as getBestAvailableBackend,Le as isBrowser,Fe as isNode,Ie as isWebWorker,$e as metrics,Ge as robustHash};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pure-md5",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "A lightweight JavaScript function for hashing messages by the MD5 algorithm",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,8 +27,9 @@
27
27
  "build:watch": "tsup --watch",
28
28
  "build:prod": "tsup --minify",
29
29
  "dev": "tsup --watch",
30
- "test": "jest --config jestconfig.json --coverage --passWithNoTests",
31
- "coverage": "codecov -f coverage/coverage-final.json",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "test:coverage": "vitest run --coverage",
32
33
  "changeset": "changeset",
33
34
  "changeset:version": "changeset version",
34
35
  "changeset:publish": "changeset publish"
@@ -39,21 +40,21 @@
39
40
  "import": "./dist/index.js",
40
41
  "require": "./dist/index.js"
41
42
  },
42
- "./core": {
43
- "types": "./dist/core/index.d.ts",
44
- "import": "./dist/core/index.js",
45
- "require": "./dist/core/index.js"
46
- },
47
- "./adapters/webcrypto": {
48
- "types": "./dist/adapters/webcrypto.d.ts",
49
- "import": "./dist/adapters/webcrypto.js",
50
- "require": "./dist/adapters/webcrypto.js"
43
+ "./md5": {
44
+ "types": "./dist/md5.d.ts",
45
+ "import": "./dist/md5.js",
46
+ "require": "./dist/md5.cjs"
51
47
  },
52
48
  "./adapters/node": {
53
49
  "types": "./dist/adapters/node.d.ts",
54
50
  "import": "./dist/adapters/node.js",
55
51
  "require": "./dist/adapters/node.js"
56
52
  },
53
+ "./adapters/webcrypto": {
54
+ "types": "./dist/adapters/webcrypto.d.ts",
55
+ "import": "./dist/adapters/webcrypto.js",
56
+ "require": "./dist/adapters/webcrypto.js"
57
+ },
57
58
  "./adapters/ie11": {
58
59
  "types": "./dist/adapters/ie11.d.ts",
59
60
  "import": "./dist/adapters/ie11.js",
@@ -79,22 +80,15 @@
79
80
  "import": "./dist/stream/index.js",
80
81
  "require": "./dist/stream/index.js"
81
82
  },
82
- "./stream/light": {
83
- "types": "./dist/stream/light/index.d.ts",
84
- "import": "./dist/stream/light/index.js",
85
- "require": "./dist/stream/light/index.js"
86
- },
87
83
  "./package.json": "./package.json"
88
84
  },
89
85
  "devDependencies": {
90
86
  "@changesets/changelog-github": "^0.5.2",
91
87
  "@changesets/cli": "^2.29.8",
92
- "@types/jest": "^29.5.14",
93
- "codecov": "^3.8.3",
94
- "jest": "^29.7.0",
95
- "ts-jest": "^29.1.5",
88
+ "@vitest/coverage-v8": "^4.1.2",
96
89
  "tsup": "^8.5.1",
97
- "typescript": "^5.6.3"
90
+ "typescript": "^5.6.3",
91
+ "vitest": "^4.1.2"
98
92
  },
99
93
  "keywords": [
100
94
  "md5"
@@ -1 +0,0 @@
1
- 'use strict';var B="0123456789abcdef".split(""),s=B;function j(m){let t="";for(let o=0;o<4;o++)t+=s[m>>o*8+4&15]+s[m>>o*8&15];return t}function v(m){let t=m.length,o=new Array(t);for(let r=0;r<t;r++)o[r]=j(m[r]);return o.join("")}var h=v;function w(m,t){return m+t&4294967295}var f=w;function _(m,t,o,r,n){let e=n||f;return t=e(e(t,m),e(o,r)),t}function q(m,t,o,r){var e=(r||f)(m<<t|m>>>32-t,o);return e}function p(m,t,o,r,n,e,u){return t=_(m,t,r,e,u),q(t,n,o,u)}function g(m,t,o,r,n,e,u,i){return p(o&r|~o&n,t,o,e,u,i,m)}function a(m,t,o,r,n,e,u,i){return p(o&n|r&~n,t,o,e,u,i,m)}function A(m,t,o,r,n,e,u,i){return p(o^r^n,t,o,e,u,i,m)}function x(m,t,o,r,n,e,u,i){return p(r^(o|~n),t,o,e,u,i,m)}function z(m,t,o){typeof o>"u"&&(o=f);let r=m[0],n=m[1],e=m[2],u=m[3],i=g.bind(null,o);r=i(r,n,e,u,t[0],7,-680876936),u=i(u,r,n,e,t[1],12,-389564586),e=i(e,u,r,n,t[2],17,606105819),n=i(n,e,u,r,t[3],22,-1044525330),r=i(r,n,e,u,t[4],7,-176418897),u=i(u,r,n,e,t[5],12,1200080426),e=i(e,u,r,n,t[6],17,-1473231341),n=i(n,e,u,r,t[7],22,-45705983),r=i(r,n,e,u,t[8],7,1770035416),u=i(u,r,n,e,t[9],12,-1958414417),e=i(e,u,r,n,t[10],17,-42063),n=i(n,e,u,r,t[11],22,-1990404162),r=i(r,n,e,u,t[12],7,1804603682),u=i(u,r,n,e,t[13],12,-40341101),e=i(e,u,r,n,t[14],17,-1502002290),n=i(n,e,u,r,t[15],22,1236535329);let b=a.bind(null,o);r=b(r,n,e,u,t[1],5,-165796510),u=b(u,r,n,e,t[6],9,-1069501632),e=b(e,u,r,n,t[11],14,643717713),n=b(n,e,u,r,t[0],20,-373897302),r=b(r,n,e,u,t[5],5,-701558691),u=b(u,r,n,e,t[10],9,38016083),e=b(e,u,r,n,t[15],14,-660478335),n=b(n,e,u,r,t[4],20,-405537848),r=b(r,n,e,u,t[9],5,568446438),u=b(u,r,n,e,t[14],9,-1019803690),e=b(e,u,r,n,t[3],14,-187363961),n=b(n,e,u,r,t[8],20,1163531501),r=b(r,n,e,u,t[13],5,-1444681467),u=b(u,r,n,e,t[2],9,-51403784),e=b(e,u,r,n,t[7],14,1735328473),n=b(n,e,u,r,t[12],20,-1926607734);let c=A.bind(null,o);r=c(r,n,e,u,t[5],4,-378558),u=c(u,r,n,e,t[8],11,-2022574463),e=c(e,u,r,n,t[11],16,1839030562),n=c(n,e,u,r,t[14],23,-35309556),r=c(r,n,e,u,t[1],4,-1530992060),u=c(u,r,n,e,t[4],11,1272893353),e=c(e,u,r,n,t[7],16,-155497632),n=c(n,e,u,r,t[10],23,-1094730640),r=c(r,n,e,u,t[13],4,681279174),u=c(u,r,n,e,t[0],11,-358537222),e=c(e,u,r,n,t[3],16,-722521979),n=c(n,e,u,r,t[6],23,76029189),r=c(r,n,e,u,t[9],4,-640364487),u=c(u,r,n,e,t[12],11,-421815835),e=c(e,u,r,n,t[15],16,530742520),n=c(n,e,u,r,t[2],23,-995338651);let d=x.bind(null,o);r=d(r,n,e,u,t[0],6,-198630844),u=d(u,r,n,e,t[7],10,1126891415),e=d(e,u,r,n,t[14],15,-1416354905),n=d(n,e,u,r,t[5],21,-57434055),r=d(r,n,e,u,t[12],6,1700485571),u=d(u,r,n,e,t[3],10,-1894986606),e=d(e,u,r,n,t[10],15,-1051523),n=d(n,e,u,r,t[1],21,-2054922799),r=d(r,n,e,u,t[8],6,1873313359),u=d(u,r,n,e,t[15],10,-30611744),e=d(e,u,r,n,t[6],15,-1560198380),n=d(n,e,u,r,t[13],21,1309151649),r=d(r,n,e,u,t[4],6,-145523070),u=d(u,r,n,e,t[11],10,-1120210379),e=d(e,u,r,n,t[2],15,718787259),n=d(n,e,u,r,t[9],21,-343485551),m[0]=o(r,m[0]),m[1]=o(n,m[1]),m[2]=o(e,m[2]),m[3]=o(u,m[3]);}var l=z;function D(m){let t=[];for(let o=0;o<64;o+=4)t[o>>2]=(m.charCodeAt(o)||0)+((m.charCodeAt(o+1)||0)<<8)+((m.charCodeAt(o+2)||0)<<16)+((m.charCodeAt(o+3)||0)<<24);return t}var y=D;function E(m,t){let o=m.length,r=[1732584193,-271733879,-1732584194,271733878],n;for(n=64;n<=o;n+=64)l(r,y(m.substring(n-64,n)),t);m=m.substring(n-64);var e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],u=m.length;for(n=0;n<u;n++)e[n>>2]|=(m.charCodeAt(n)&255)<<(n%4<<3);if(e[n>>2]|=128<<(n%4<<3),n>55)for(l(r,e,t),n=16;n--;)e[n]=0;return e[14]=o*8,l(r,e,t),r}var F=E;function G(m,t){let o=m.length,r=[1732584193,-271733879,-1732584194,271733878],n;for(n=64;n<=o;n+=64){let i=H(m,n-64);l(r,i,t);}let e=o-n+64,u=new Array(16).fill(0);for(let i=0;i<e;i++)u[i>>2]|=(m[o-e+i]&255)<<(i%4<<3);if(u[e>>2]|=128<<(e%4<<3),e>55){l(r,u,t);for(let i=0;i<16;i++)u[i]=0;}return u[14]=o*8,u[15]=0,l(r,u,t),r}function H(m,t){let o=[];for(let r=0;r<64;r+=4)o[r>>2]=(m[t+r]||0)+((m[t+r+1]||0)<<8)+((m[t+r+2]||0)<<16)+((m[t+r+3]||0)<<24);return o}var C=G;function k(m){return h(F(m,f))}function nn(m){return h(C(m,f))}exports.md5=k;exports.md5Buffer=nn;exports.md5Core=k;
@@ -1,19 +0,0 @@
1
- /**
2
- * Core MD5 implementation - Pure JavaScript
3
- * No dependencies, no environment detection
4
- * This is the minimal, tree-shakeable core
5
- */
6
- /**
7
- * Compute MD5 hash of a string
8
- * @param string - Input string to hash
9
- * @returns MD5 hash as hex string
10
- */
11
- declare function md5Core(string: string): string;
12
- /**
13
- * Compute MD5 hash of a Buffer
14
- * @param buffer - Input Buffer to hash
15
- * @returns MD5 hash as hex string
16
- */
17
- declare function md5Buffer(buffer: Buffer): string;
18
-
19
- export { md5Core as md5, md5Buffer, md5Core };
@@ -1,19 +0,0 @@
1
- /**
2
- * Core MD5 implementation - Pure JavaScript
3
- * No dependencies, no environment detection
4
- * This is the minimal, tree-shakeable core
5
- */
6
- /**
7
- * Compute MD5 hash of a string
8
- * @param string - Input string to hash
9
- * @returns MD5 hash as hex string
10
- */
11
- declare function md5Core(string: string): string;
12
- /**
13
- * Compute MD5 hash of a Buffer
14
- * @param buffer - Input Buffer to hash
15
- * @returns MD5 hash as hex string
16
- */
17
- declare function md5Buffer(buffer: Buffer): string;
18
-
19
- export { md5Core as md5, md5Buffer, md5Core };
@@ -1 +0,0 @@
1
- export{a as md5,b as md5Buffer,a as md5Core}from'../chunk-Z4JB6DTM.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';