pure-md5 0.2.1 → 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.
- package/README.md +38 -24
- package/dist/adapters/ie11.js +1 -1
- package/dist/adapters/node.js +1 -1
- package/dist/adapters/webcrypto.js +1 -1
- package/dist/index.d.ts +149 -5
- package/dist/index.js +3 -1
- package/dist/md5.cjs +1 -0
- package/dist/md5.d.ts +20 -0
- package/dist/md5.js +1 -0
- package/dist/stream/md5-stream.js +1 -1
- package/dist/stream/whatwg-stream.js +1 -1
- package/dist/utils/detect.js +3 -1
- package/package.json +10 -15
- package/pure-md5-0.2.1.tgz +0 -0
- package/test-tree-shake.mjs +12 -0
- package/dist/core/index.cjs +0 -1
- package/dist/core/index.d.cts +0 -19
- package/dist/core/index.d.ts +0 -19
- package/dist/core/index.js +0 -1
- package/dist/index.d.cts +0 -84
- package/dist/stream/adapter.cjs +0 -1
- package/dist/stream/adapter.d.cts +0 -63
- package/dist/stream/adapter.d.ts +0 -63
- package/dist/stream/adapter.js +0 -1
- package/dist/stream/fs-utils.cjs +0 -1
- package/dist/stream/fs-utils.d.cts +0 -137
- package/dist/stream/fs-utils.d.ts +0 -137
- package/dist/stream/fs-utils.js +0 -1
- package/dist/stream/index.cjs +0 -1
- package/dist/stream/index.d.cts +0 -4
- package/dist/stream/index.d.ts +0 -4
- package/dist/stream/index.js +0 -1
- package/dist/stream/light/index.cjs +0 -1
- package/dist/stream/light/index.d.cts +0 -4
- package/dist/stream/light/index.d.ts +0 -4
- package/dist/stream/light/index.js +0 -1
- package/dist/types-edGoGJ5V.d.cts +0 -42
- package/dist/types-edGoGJ5V.d.ts +0 -42
- package/pure-md5-0.2.0.tgz +0 -0
package/dist/index.d.cts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export { md5 as md5Core, md5 as md5Original } from './core/index.cjs';
|
|
2
|
-
export { WebCryptoBackend } from './adapters/webcrypto.cjs';
|
|
3
|
-
export { NodeCryptoBackend } from './adapters/node.cjs';
|
|
4
|
-
export { IE11Backend } from './adapters/ie11.cjs';
|
|
5
|
-
import { M as MD5Backend } from './types-edGoGJ5V.cjs';
|
|
6
|
-
export { MD5Result, MD5Stream, createMD5Stream, fromStream, pipeThroughMD5 } from './stream/md5-stream.cjs';
|
|
7
|
-
export { HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile } from './stream/fs-utils.cjs';
|
|
8
|
-
export { BackendDetector, FallbackManager, MetricsCollector, detector, fallbackManager, getAllAvailableBackends, getBestAvailableBackend, metrics, robustHash } from './utils/detect.cjs';
|
|
9
|
-
import 'stream';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Pure JavaScript Backend
|
|
13
|
-
* Uses the internal md5Core implementation
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
declare class PureJSBackend implements MD5Backend {
|
|
17
|
-
name: string;
|
|
18
|
-
version: string;
|
|
19
|
-
private state;
|
|
20
|
-
constructor();
|
|
21
|
-
hash(data: string): string;
|
|
22
|
-
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
23
|
-
update(data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
24
|
-
digest(encoding?: "hex" | "buffer"): string | Uint8Array | Promise<string | Uint8Array>;
|
|
25
|
-
reset(): void | Promise<void>;
|
|
26
|
-
static isAvailable(): boolean;
|
|
27
|
-
private hexToBuffer;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Pure MD5 - Unified adapter with auto-detection
|
|
32
|
-
* Supports multiple backends: Web Crypto, Node.js crypto, IE11, and Pure JS
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Default MD5 adapter with auto-detection
|
|
37
|
-
*/
|
|
38
|
-
declare class MD5Adapter {
|
|
39
|
-
private backend;
|
|
40
|
-
private backendName;
|
|
41
|
-
/**
|
|
42
|
-
* Hash string data with automatic backend selection
|
|
43
|
-
* @param data - String to hash
|
|
44
|
-
* @returns MD5 hash as hex string
|
|
45
|
-
*/
|
|
46
|
-
hash(data: string): Promise<string>;
|
|
47
|
-
/**
|
|
48
|
-
* Hash binary data with automatic backend selection
|
|
49
|
-
* @param data - Binary data to hash
|
|
50
|
-
* @returns MD5 hash as hex string
|
|
51
|
-
*/
|
|
52
|
-
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
53
|
-
/**
|
|
54
|
-
* Get backend name
|
|
55
|
-
* @returns Name of the selected backend
|
|
56
|
-
*/
|
|
57
|
-
getBackendName(): Promise<string>;
|
|
58
|
-
/**
|
|
59
|
-
* Get available backends
|
|
60
|
-
* @returns List of available backend names
|
|
61
|
-
*/
|
|
62
|
-
static getAvailableBackends(): Promise<string[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Force specific backend for all operations
|
|
65
|
-
* @param backendName - Backend name to use
|
|
66
|
-
*/
|
|
67
|
-
useBackend(backendName: string): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Create backend by name
|
|
70
|
-
* @param name - Backend name
|
|
71
|
-
* @returns Backend instance
|
|
72
|
-
*/
|
|
73
|
-
private createBackendByName;
|
|
74
|
-
/**
|
|
75
|
-
* Get backend instance (lazy initialization)
|
|
76
|
-
* @returns Backend instance
|
|
77
|
-
*/
|
|
78
|
-
private getBackend;
|
|
79
|
-
}
|
|
80
|
-
declare function md5(data: string): string;
|
|
81
|
-
declare const md5Adapter: MD5Adapter;
|
|
82
|
-
declare function md5Async(data: string): Promise<string>;
|
|
83
|
-
|
|
84
|
-
export { MD5Backend, PureJSBackend, md5, md5Adapter, md5Async };
|
package/dist/stream/adapter.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var stream=require('stream');function x(o,n){return o+n&4294967295}var l=x;function v(o,n,i,e,r){let t=r||l;return n=t(t(n,o),t(i,e)),n}function L(o,n,i,e){var t=(e||l)(o<<n|o>>>32-n,i);return t}function y(o,n,i,e,r,t,s){return n=v(o,n,e,t,s),L(n,r,i,s)}function M(o,n,i,e,r,t,s,a){return y(i&e|~i&r,n,i,t,s,a,o)}function D(o,n,i,e,r,t,s,a){return y(i&r|e&~r,n,i,t,s,a,o)}function A(o,n,i,e,r,t,s,a){return y(i^e^r,n,i,t,s,a,o)}function w(o,n,i,e,r,t,s,a){return y(e^(i|~r),n,i,t,s,a,o)}function R(o,n,i){typeof i>"u"&&(i=l);let e=o[0],r=o[1],t=o[2],s=o[3],a=M.bind(null,i);e=a(e,r,t,s,n[0],7,-680876936),s=a(s,e,r,t,n[1],12,-389564586),t=a(t,s,e,r,n[2],17,606105819),r=a(r,t,s,e,n[3],22,-1044525330),e=a(e,r,t,s,n[4],7,-176418897),s=a(s,e,r,t,n[5],12,1200080426),t=a(t,s,e,r,n[6],17,-1473231341),r=a(r,t,s,e,n[7],22,-45705983),e=a(e,r,t,s,n[8],7,1770035416),s=a(s,e,r,t,n[9],12,-1958414417),t=a(t,s,e,r,n[10],17,-42063),r=a(r,t,s,e,n[11],22,-1990404162),e=a(e,r,t,s,n[12],7,1804603682),s=a(s,e,r,t,n[13],12,-40341101),t=a(t,s,e,r,n[14],17,-1502002290),r=a(r,t,s,e,n[15],22,1236535329);let u=D.bind(null,i);e=u(e,r,t,s,n[1],5,-165796510),s=u(s,e,r,t,n[6],9,-1069501632),t=u(t,s,e,r,n[11],14,643717713),r=u(r,t,s,e,n[0],20,-373897302),e=u(e,r,t,s,n[5],5,-701558691),s=u(s,e,r,t,n[10],9,38016083),t=u(t,s,e,r,n[15],14,-660478335),r=u(r,t,s,e,n[4],20,-405537848),e=u(e,r,t,s,n[9],5,568446438),s=u(s,e,r,t,n[14],9,-1019803690),t=u(t,s,e,r,n[3],14,-187363961),r=u(r,t,s,e,n[8],20,1163531501),e=u(e,r,t,s,n[13],5,-1444681467),s=u(s,e,r,t,n[2],9,-51403784),t=u(t,s,e,r,n[7],14,1735328473),r=u(r,t,s,e,n[12],20,-1926607734);let f=A.bind(null,i);e=f(e,r,t,s,n[5],4,-378558),s=f(s,e,r,t,n[8],11,-2022574463),t=f(t,s,e,r,n[11],16,1839030562),r=f(r,t,s,e,n[14],23,-35309556),e=f(e,r,t,s,n[1],4,-1530992060),s=f(s,e,r,t,n[4],11,1272893353),t=f(t,s,e,r,n[7],16,-155497632),r=f(r,t,s,e,n[10],23,-1094730640),e=f(e,r,t,s,n[13],4,681279174),s=f(s,e,r,t,n[0],11,-358537222),t=f(t,s,e,r,n[3],16,-722521979),r=f(r,t,s,e,n[6],23,76029189),e=f(e,r,t,s,n[9],4,-640364487),s=f(s,e,r,t,n[12],11,-421815835),t=f(t,s,e,r,n[15],16,530742520),r=f(r,t,s,e,n[2],23,-995338651);let m=w.bind(null,i);e=m(e,r,t,s,n[0],6,-198630844),s=m(s,e,r,t,n[7],10,1126891415),t=m(t,s,e,r,n[14],15,-1416354905),r=m(r,t,s,e,n[5],21,-57434055),e=m(e,r,t,s,n[12],6,1700485571),s=m(s,e,r,t,n[3],10,-1894986606),t=m(t,s,e,r,n[10],15,-1051523),r=m(r,t,s,e,n[1],21,-2054922799),e=m(e,r,t,s,n[8],6,1873313359),s=m(s,e,r,t,n[15],10,-30611744),t=m(t,s,e,r,n[6],15,-1560198380),r=m(r,t,s,e,n[13],21,1309151649),e=m(e,r,t,s,n[4],6,-145523070),s=m(s,e,r,t,n[11],10,-1120210379),t=m(t,s,e,r,n[2],15,718787259),r=m(r,t,s,e,n[9],21,-343485551),o[0]=i(e,o[0]),o[1]=i(r,o[1]),o[2]=i(t,o[2]),o[3]=i(s,o[3]);}var p=R;var W="0123456789abcdef".split(""),S=W;function U(o){let n="";for(let i=0;i<4;i++)n+=S[o>>i*8+4&15]+S[o>>i*8&15];return n}function C(o){let n=o.length,i=new Array(n);for(let e=0;e<n;e++)i[e]=U(o[e]);return i.join("")}var B=C;var g=class o extends stream.Transform{constructor(i){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=i?.add32||l,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(i,e,r){try{let t=i,s=t.length;if(s===0){r();return}if(this.state.bufferLength>0){let f=this.state.bufferLength,m=64-f,c=Math.min(s,m);for(let b=0;b<c;b++)this.buffer[f+b]=t[b];if(this.state.bufferLength+=c,this.state.bufferLength===64&&this._processBufferBlock(),c===s){r();return}let d=s-c;for(let b=0;b<d;b++)t[b]=t[c+b];let h=Buffer.alloc(d);for(let b=0;b<d;b++)h[b]=t[b];t=h;}let a=Math.floor(t.length/64);for(let f=0;f<a;f++){let m=f*64,c=[];for(let d=0;d<16;d++){let h=m+d*4;c[d]=t[h]+(t[h+1]<<8)+(t[h+2]<<16)+(t[h+3]<<24);}p(this.state.state,c,this.add32),this.state.bytesProcessed+=64;}let u=t.length%64;if(u>0){this.buffer.length<u&&(this.buffer=new Uint8Array(u),this.state.buffer=this.buffer);for(let f=0;f<u;f++)this.buffer[f]=t[a*64+f];this.state.bufferLength=u;}r();}catch(t){r(t);}}_processBufferBlock(){let i=this.state.buffer,e=[];for(let r=0;r<16;r++){let t=r*4;e[r]=i[t]+(i[t+1]<<8)+(i[t+2]<<16)+(i[t+3]<<24);}p(this.state.state,e,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(i){try{let{state:e,bufferLength:r,buffer:t}=this.state,s=new Array(16).fill(0);for(let u=0;u<r;u++)s[u>>2]|=(t[u]&255)<<(u%4<<3);if(s[r>>2]|=128<<(r%4<<3),r>55){p(e,s,this.add32);for(let u=0;u<16;u++)s[u]=0;}s[14]=(this.state.bytesProcessed+r)*8,s[15]=0,p(e,s,this.add32);let a=B(e);this.emit("md5",{digest:a,bytesProcessed:this.state.bytesProcessed+r}),i();}catch(e){i(e);}}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(i,e){let r=new o(e),t=T.call(r,i);return {stream:r,result:t}}};async function T(o){return new Promise((n,i)=>{let e=[];o.pipe(this).on("md5",r=>{e.push(r);}).on("error",i).on("finish",()=>{n(e[0]);});})}var P=class{constructor(){this.name="stream";this.version="0.1.0";this.state=null;}initNodeStream(n){this.state={stream:n,type:"node"};}initWhatWGStream(n){this.state={stream:n,type:"whatwg"};}async hash(n){let i=new g;return (await new Promise((r,t)=>{i.on("md5",s=>r(s)).on("error",t).end(n);})).digest}async hashBinary(n){let i=new g,e;return n instanceof Uint8Array?e=Buffer.from(n):n instanceof ArrayBuffer?e=Buffer.from(new Uint8Array(n)):e=Buffer.from(n),(await new Promise((t,s)=>{i.on("md5",a=>t(a)).on("error",s).end(e);})).digest}update(n){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let i=this.state.stream,e;typeof n=="string"||n instanceof Uint8Array?e=Buffer.from(n):n instanceof ArrayBuffer?e=Buffer.from(new Uint8Array(n)):e=Buffer.from(n),i.write(e);}}digest(n){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let i=this.state.stream;return i.end(),new Promise((e,r)=>{i.on("md5",t=>{if(n==="buffer"){let s=t.digest,a=[];for(let u=0;u<s.length;u+=2)a.push(parseInt(s.substring(u,u+2),16));e(Buffer.from(a));}else e(t.digest);}).on("error",r);})}else return this.state.stream.getResult().then(e=>e.digest)}reset(){this.state&&this.state.type==="node"&&this.state.stream.reset();}static isAvailable(){return true}};exports.StreamBackend=P;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { M as MD5Backend } from '../types-edGoGJ5V.cjs';
|
|
2
|
-
import { MD5Stream } from './md5-stream.cjs';
|
|
3
|
-
import { MD5ReadableStream } from './whatwg-stream.cjs';
|
|
4
|
-
import 'stream';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Stream Backend Adapter
|
|
8
|
-
* Integrates MD5 stream computation with backend detection system
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Stream backend for MD5 operations that supports streaming
|
|
13
|
-
* Can be used with both Node.js streams and WHATWG streams
|
|
14
|
-
*/
|
|
15
|
-
declare class StreamBackend implements MD5Backend {
|
|
16
|
-
name: string;
|
|
17
|
-
version: string;
|
|
18
|
-
private state;
|
|
19
|
-
/**
|
|
20
|
-
* Initialize with Node.js stream
|
|
21
|
-
* @param stream Node.js Transform stream
|
|
22
|
-
*/
|
|
23
|
-
initNodeStream(stream: MD5Stream): void;
|
|
24
|
-
/**
|
|
25
|
-
* Initialize with WHATWG stream
|
|
26
|
-
* @param stream WHATWG ReadableStream
|
|
27
|
-
*/
|
|
28
|
-
initWhatWGStream(stream: MD5ReadableStream): void;
|
|
29
|
-
/**
|
|
30
|
-
* Hash string data (converts to stream internally)
|
|
31
|
-
* @param data String to hash
|
|
32
|
-
* @returns MD5 hash as hex string
|
|
33
|
-
*/
|
|
34
|
-
hash(data: string): Promise<string>;
|
|
35
|
-
/**
|
|
36
|
-
* Hash binary data (converts to stream internally)
|
|
37
|
-
* @param data Binary data to hash
|
|
38
|
-
* @returns MD5 hash as hex string
|
|
39
|
-
*/
|
|
40
|
-
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
41
|
-
/**
|
|
42
|
-
* Update hash with additional data (streaming)
|
|
43
|
-
* @param data Data to add to hash
|
|
44
|
-
*/
|
|
45
|
-
update(data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Get final hash digest
|
|
48
|
-
* @param encoding Output encoding ('hex' or 'buffer')
|
|
49
|
-
* @returns Hash digest
|
|
50
|
-
*/
|
|
51
|
-
digest(encoding?: 'hex' | 'buffer'): string | Uint8Array | Promise<string | Uint8Array>;
|
|
52
|
-
/**
|
|
53
|
-
* Reset the hash state
|
|
54
|
-
*/
|
|
55
|
-
reset(): void | Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Check if backend is available
|
|
58
|
-
* @returns Always true for stream backend
|
|
59
|
-
*/
|
|
60
|
-
static isAvailable(): boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { StreamBackend };
|
package/dist/stream/adapter.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { M as MD5Backend } from '../types-edGoGJ5V.js';
|
|
2
|
-
import { MD5Stream } from './md5-stream.js';
|
|
3
|
-
import { MD5ReadableStream } from './whatwg-stream.js';
|
|
4
|
-
import 'stream';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Stream Backend Adapter
|
|
8
|
-
* Integrates MD5 stream computation with backend detection system
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Stream backend for MD5 operations that supports streaming
|
|
13
|
-
* Can be used with both Node.js streams and WHATWG streams
|
|
14
|
-
*/
|
|
15
|
-
declare class StreamBackend implements MD5Backend {
|
|
16
|
-
name: string;
|
|
17
|
-
version: string;
|
|
18
|
-
private state;
|
|
19
|
-
/**
|
|
20
|
-
* Initialize with Node.js stream
|
|
21
|
-
* @param stream Node.js Transform stream
|
|
22
|
-
*/
|
|
23
|
-
initNodeStream(stream: MD5Stream): void;
|
|
24
|
-
/**
|
|
25
|
-
* Initialize with WHATWG stream
|
|
26
|
-
* @param stream WHATWG ReadableStream
|
|
27
|
-
*/
|
|
28
|
-
initWhatWGStream(stream: MD5ReadableStream): void;
|
|
29
|
-
/**
|
|
30
|
-
* Hash string data (converts to stream internally)
|
|
31
|
-
* @param data String to hash
|
|
32
|
-
* @returns MD5 hash as hex string
|
|
33
|
-
*/
|
|
34
|
-
hash(data: string): Promise<string>;
|
|
35
|
-
/**
|
|
36
|
-
* Hash binary data (converts to stream internally)
|
|
37
|
-
* @param data Binary data to hash
|
|
38
|
-
* @returns MD5 hash as hex string
|
|
39
|
-
*/
|
|
40
|
-
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
41
|
-
/**
|
|
42
|
-
* Update hash with additional data (streaming)
|
|
43
|
-
* @param data Data to add to hash
|
|
44
|
-
*/
|
|
45
|
-
update(data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Get final hash digest
|
|
48
|
-
* @param encoding Output encoding ('hex' or 'buffer')
|
|
49
|
-
* @returns Hash digest
|
|
50
|
-
*/
|
|
51
|
-
digest(encoding?: 'hex' | 'buffer'): string | Uint8Array | Promise<string | Uint8Array>;
|
|
52
|
-
/**
|
|
53
|
-
* Reset the hash state
|
|
54
|
-
*/
|
|
55
|
-
reset(): void | Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Check if backend is available
|
|
58
|
-
* @returns Always true for stream backend
|
|
59
|
-
*/
|
|
60
|
-
static isAvailable(): boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { StreamBackend };
|
package/dist/stream/adapter.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{a as StreamBackend}from'../chunk-Y2ZKN4NS.js';import'../chunk-MIU3X4SB.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
|
package/dist/stream/fs-utils.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var g=require('fs'),stream=require('stream');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);function E(o,n){return o+n&4294967295}var b=E;function C(o,n,i,e,t){let r=t||b;return n=r(r(n,o),r(i,e)),n}function O(o,n,i,e){var r=(e||b)(o<<n|o>>>32-n,i);return r}function y(o,n,i,e,t,r,s){return n=C(o,n,e,r,s),O(n,t,i,s)}function S(o,n,i,e,t,r,s,u){return y(i&e|~i&t,n,i,r,s,u,o)}function D(o,n,i,e,t,r,s,u){return y(i&t|e&~t,n,i,r,s,u,o)}function F(o,n,i,e,t,r,s,u){return y(i^e^t,n,i,r,s,u,o)}function v(o,n,i,e,t,r,s,u){return y(e^(i|~t),n,i,r,s,u,o)}function $(o,n,i){typeof i>"u"&&(i=b);let e=o[0],t=o[1],r=o[2],s=o[3],u=S.bind(null,i);e=u(e,t,r,s,n[0],7,-680876936),s=u(s,e,t,r,n[1],12,-389564586),r=u(r,s,e,t,n[2],17,606105819),t=u(t,r,s,e,n[3],22,-1044525330),e=u(e,t,r,s,n[4],7,-176418897),s=u(s,e,t,r,n[5],12,1200080426),r=u(r,s,e,t,n[6],17,-1473231341),t=u(t,r,s,e,n[7],22,-45705983),e=u(e,t,r,s,n[8],7,1770035416),s=u(s,e,t,r,n[9],12,-1958414417),r=u(r,s,e,t,n[10],17,-42063),t=u(t,r,s,e,n[11],22,-1990404162),e=u(e,t,r,s,n[12],7,1804603682),s=u(s,e,t,r,n[13],12,-40341101),r=u(r,s,e,t,n[14],17,-1502002290),t=u(t,r,s,e,n[15],22,1236535329);let a=D.bind(null,i);e=a(e,t,r,s,n[1],5,-165796510),s=a(s,e,t,r,n[6],9,-1069501632),r=a(r,s,e,t,n[11],14,643717713),t=a(t,r,s,e,n[0],20,-373897302),e=a(e,t,r,s,n[5],5,-701558691),s=a(s,e,t,r,n[10],9,38016083),r=a(r,s,e,t,n[15],14,-660478335),t=a(t,r,s,e,n[4],20,-405537848),e=a(e,t,r,s,n[9],5,568446438),s=a(s,e,t,r,n[14],9,-1019803690),r=a(r,s,e,t,n[3],14,-187363961),t=a(t,r,s,e,n[8],20,1163531501),e=a(e,t,r,s,n[13],5,-1444681467),s=a(s,e,t,r,n[2],9,-51403784),r=a(r,s,e,t,n[7],14,1735328473),t=a(t,r,s,e,n[12],20,-1926607734);let f=F.bind(null,i);e=f(e,t,r,s,n[5],4,-378558),s=f(s,e,t,r,n[8],11,-2022574463),r=f(r,s,e,t,n[11],16,1839030562),t=f(t,r,s,e,n[14],23,-35309556),e=f(e,t,r,s,n[1],4,-1530992060),s=f(s,e,t,r,n[4],11,1272893353),r=f(r,s,e,t,n[7],16,-155497632),t=f(t,r,s,e,n[10],23,-1094730640),e=f(e,t,r,s,n[13],4,681279174),s=f(s,e,t,r,n[0],11,-358537222),r=f(r,s,e,t,n[3],16,-722521979),t=f(t,r,s,e,n[6],23,76029189),e=f(e,t,r,s,n[9],4,-640364487),s=f(s,e,t,r,n[12],11,-421815835),r=f(r,s,e,t,n[15],16,530742520),t=f(t,r,s,e,n[2],23,-995338651);let m=v.bind(null,i);e=m(e,t,r,s,n[0],6,-198630844),s=m(s,e,t,r,n[7],10,1126891415),r=m(r,s,e,t,n[14],15,-1416354905),t=m(t,r,s,e,n[5],21,-57434055),e=m(e,t,r,s,n[12],6,1700485571),s=m(s,e,t,r,n[3],10,-1894986606),r=m(r,s,e,t,n[10],15,-1051523),t=m(t,r,s,e,n[1],21,-2054922799),e=m(e,t,r,s,n[8],6,1873313359),s=m(s,e,t,r,n[15],10,-30611744),r=m(r,s,e,t,n[6],15,-1560198380),t=m(t,r,s,e,n[13],21,1309151649),e=m(e,t,r,s,n[4],6,-145523070),s=m(s,e,t,r,n[11],10,-1120210379),r=m(r,s,e,t,n[2],15,718787259),t=m(t,r,s,e,n[9],21,-343485551),o[0]=i(e,o[0]),o[1]=i(t,o[1]),o[2]=i(r,o[2]),o[3]=i(s,o[3]);}var d=$;var j="0123456789abcdef".split(""),x=j;function T(o){let n="";for(let i=0;i<4;i++)n+=x[o>>i*8+4&15]+x[o>>i*8&15];return n}function _(o){let n=o.length,i=new Array(n);for(let e=0;e<n;e++)i[e]=T(o[e]);return i.join("")}var w=_;var M=class o extends stream.Transform{constructor(i){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=i?.add32||b,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(i,e,t){try{let r=i,s=r.length;if(s===0){t();return}if(this.state.bufferLength>0){let f=this.state.bufferLength,m=64-f,l=Math.min(s,m);for(let c=0;c<l;c++)this.buffer[f+c]=r[c];if(this.state.bufferLength+=l,this.state.bufferLength===64&&this._processBufferBlock(),l===s){t();return}let h=s-l;for(let c=0;c<h;c++)r[c]=r[l+c];let p=Buffer.alloc(h);for(let c=0;c<h;c++)p[c]=r[c];r=p;}let u=Math.floor(r.length/64);for(let f=0;f<u;f++){let m=f*64,l=[];for(let h=0;h<16;h++){let p=m+h*4;l[h]=r[p]+(r[p+1]<<8)+(r[p+2]<<16)+(r[p+3]<<24);}d(this.state.state,l,this.add32),this.state.bytesProcessed+=64;}let a=r.length%64;if(a>0){this.buffer.length<a&&(this.buffer=new Uint8Array(a),this.state.buffer=this.buffer);for(let f=0;f<a;f++)this.buffer[f]=r[u*64+f];this.state.bufferLength=a;}t();}catch(r){t(r);}}_processBufferBlock(){let i=this.state.buffer,e=[];for(let t=0;t<16;t++){let r=t*4;e[t]=i[r]+(i[r+1]<<8)+(i[r+2]<<16)+(i[r+3]<<24);}d(this.state.state,e,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(i){try{let{state:e,bufferLength:t,buffer:r}=this.state,s=new Array(16).fill(0);for(let a=0;a<t;a++)s[a>>2]|=(r[a]&255)<<(a%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55){d(e,s,this.add32);for(let a=0;a<16;a++)s[a]=0;}s[14]=(this.state.bytesProcessed+t)*8,s[15]=0,d(e,s,this.add32);let u=w(e);this.emit("md5",{digest:u,bytesProcessed:this.state.bytesProcessed+t}),i();}catch(e){i(e);}}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(i,e){let t=new o(e),r=U.call(t,i);return {stream:t,result:r}}};function B(o){return new M(o)}async function U(o){return new Promise((n,i)=>{let e=[];o.pipe(this).on("md5",t=>{e.push(t);}).on("error",i).on("finish",()=>{n(e[0]);});})}function H(o,n){let i=o.length,e=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=i;t+=64){let u=I(o,t-64);d(e,u,n);}let r=i-t+64,s=new Array(16).fill(0);for(let u=0;u<r;u++)s[u>>2]|=(o[i-r+u]&255)<<(u%4<<3);if(s[r>>2]|=128<<(r%4<<3),r>55){d(e,s,n);for(let u=0;u<16;u++)s[u]=0;}return s[14]=i*8,s[15]=0,d(e,s,n),e}function I(o,n){let i=[];for(let e=0;e<64;e+=4)i[e>>2]=(o[n+e]||0)+((o[n+e+1]||0)<<8)+((o[n+e+2]||0)<<16)+((o[n+e+3]||0)<<24);return i}var P=H;function A(o){return w(P(o,b))}async function R(o,n={}){if(typeof o!="string"||o.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!g__default.default.existsSync(o))throw new Error(`File not found: ${o}`);let i;try{i=g__default.default.statSync(o);}catch(t){throw new Error(`Failed to access file ${o}: ${t.message}`)}if(!i.isFile())throw new Error(`Path is not a file: ${o}`);let e=g__default.default.createReadStream(o,{highWaterMark:n.chunkSize||64*1024});try{return await L(e,{onProgress:n.onProgress,totalSize:i.size})}finally{e.destroy();}}async function L(o,n={}){if(!o||typeof o.on!="function")throw new Error("Invalid readable stream: stream must have event listener support");let i=B(),e=0;return n.onProgress&&o.on("data",t=>{e+=t.length,n.onProgress?.(e);}),o.on("error",t=>{i.destroy(t);}),o.on("end",()=>{i.end();}),new Promise((t,r)=>{i.on("md5",s=>{t(s);}).on("error",s=>{r(s);}),o.pipe(i);})}async function de(o,n={}){return (await R(o,n)).digest}async function le(o,n={}){return (await L(o,n)).digest}async function he(o,n,i={}){return (await R(o,i)).digest.toLowerCase()===n.toLowerCase()}function pe(o){if(typeof o!="string"||o.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!g__default.default.existsSync(o))throw new Error(`File not found: ${o}`);let n;try{n=g__default.default.statSync(o);}catch(e){throw new Error(`Failed to access file ${o}: ${e.message}`)}if(!n.isFile())throw new Error(`Path is not a file: ${o}`);let i;try{i=g__default.default.readFileSync(o);}catch(e){throw new Error(`Failed to read file ${o}: ${e.message}`)}return A(i)}function ge(o,n){let i=0;return e=>{if(o>0){let t=Math.min(100,e/o*100);Math.floor(t)!==Math.floor(i)&&(n(t),i=t);}}}exports.createProgressTracker=ge;exports.hashFile=R;exports.hashFileDigest=de;exports.hashFileStream=L;exports.hashFileStreamDigest=le;exports.hashFileSync=pe;exports.verifyFile=he;
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
import { MD5Result } from './md5-stream.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* File System Utilities for MD5 hashing
|
|
6
|
-
* Provides convenient utilities for hashing files through Node.js file system streams
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Options for file hashing operations
|
|
11
|
-
*/
|
|
12
|
-
interface HashFileOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Chunk size for reading file (default: 64KB)
|
|
15
|
-
*/
|
|
16
|
-
chunkSize?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Progress callback for tracking hashing progress
|
|
19
|
-
* @param current - Current position in bytes
|
|
20
|
-
*/
|
|
21
|
-
onProgress?: (current: number) => void;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Hash a file by its path
|
|
25
|
-
* @param filePath - Path to the file to hash
|
|
26
|
-
* @param options - Optional configuration
|
|
27
|
-
* @returns Promise with MD5 result (digest and bytes processed)
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* import { hashFile } from 'pure-md5';
|
|
32
|
-
*
|
|
33
|
-
* const result = await hashFile('path/to/file.txt');
|
|
34
|
-
* console.log('MD5:', result.digest);
|
|
35
|
-
* console.log('Bytes:', result.bytesProcessed);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
declare function hashFile(filePath: string, options?: HashFileOptions): Promise<MD5Result>;
|
|
39
|
-
/**
|
|
40
|
-
* Hash data from an existing readable stream
|
|
41
|
-
* @param readStream - Readable stream to hash
|
|
42
|
-
* @param options - Optional configuration
|
|
43
|
-
* @returns Promise with MD5 result (digest and bytes processed)
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { createReadStream } from 'fs';
|
|
48
|
-
* import { hashFileStream } from 'pure-md5';
|
|
49
|
-
*
|
|
50
|
-
* const stream = createReadStream('path/to/file.txt');
|
|
51
|
-
* const result = await hashFileStream(stream);
|
|
52
|
-
* console.log('MD5:', result.digest);
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
declare function hashFileStream(readStream: Readable, options?: {
|
|
56
|
-
onProgress?: (current: number) => void;
|
|
57
|
-
totalSize?: number;
|
|
58
|
-
}): Promise<MD5Result>;
|
|
59
|
-
/**
|
|
60
|
-
* Hash a file and return only the hex digest
|
|
61
|
-
* @param filePath - Path to the file to hash
|
|
62
|
-
* @param options - Optional configuration
|
|
63
|
-
* @returns Promise with MD5 hex digest string
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* import { hashFileDigest } from 'pure-md5';
|
|
68
|
-
*
|
|
69
|
-
* const digest = await hashFileDigest('path/to/file.txt');
|
|
70
|
-
* console.log('MD5:', digest);
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
declare function hashFileDigest(filePath: string, options?: HashFileOptions): Promise<string>;
|
|
74
|
-
/**
|
|
75
|
-
* Hash a file stream and return only the hex digest
|
|
76
|
-
* @param readStream - Readable stream to hash
|
|
77
|
-
* @param options - Optional configuration
|
|
78
|
-
* @returns Promise with MD5 hex digest string
|
|
79
|
-
*/
|
|
80
|
-
declare function hashFileStreamDigest(readStream: Readable, options?: {
|
|
81
|
-
onProgress?: (current: number) => void;
|
|
82
|
-
totalSize?: number;
|
|
83
|
-
}): Promise<string>;
|
|
84
|
-
/**
|
|
85
|
-
* Verify file integrity by comparing MD5 hash
|
|
86
|
-
* @param filePath - Path to the file to verify
|
|
87
|
-
* @param expectedDigest - Expected MD5 hex digest
|
|
88
|
-
* @param options - Optional configuration
|
|
89
|
-
* @returns Promise with verification result
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```ts
|
|
93
|
-
* import { verifyFile } from 'pure-md5';
|
|
94
|
-
*
|
|
95
|
-
* const isVerified = await verifyFile(
|
|
96
|
-
* 'path/to/file.txt',
|
|
97
|
-
* '5d41402abc4b2a76b9719d911017c592'
|
|
98
|
-
* );
|
|
99
|
-
* console.log('Verified:', isVerified);
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare function verifyFile(filePath: string, expectedDigest: string, options?: HashFileOptions): Promise<boolean>;
|
|
103
|
-
/**
|
|
104
|
-
* Get MD5 hash of a file synchronously (not recommended for large files)
|
|
105
|
-
* @param filePath - Path to the file to hash
|
|
106
|
-
* @returns MD5 hex digest string
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* import { hashFileSync } from 'pure-md5';
|
|
111
|
-
*
|
|
112
|
-
* const digest = hashFileSync('path/to/file.txt');
|
|
113
|
-
* console.log('MD5:', digest);
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
declare function hashFileSync(filePath: string): string;
|
|
117
|
-
/**
|
|
118
|
-
* Utility to create a progress tracker for file hashing
|
|
119
|
-
* @param totalSize - Total size of the file being hashed
|
|
120
|
-
* @param onUpdate - Callback with progress percentage (0-100)
|
|
121
|
-
* @returns Progress callback function
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* import { hashFile, createProgressTracker } from 'pure-md5';
|
|
126
|
-
*
|
|
127
|
-
* const totalSize = 1024 * 1024 * 100; // 100MB
|
|
128
|
-
* const progress = createProgressTracker(totalSize, (percent) => {
|
|
129
|
-
* console.log(`Progress: ${percent.toFixed(1)}%`);
|
|
130
|
-
* });
|
|
131
|
-
*
|
|
132
|
-
* const result = await hashFile('large-file.bin', { onProgress: progress });
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
declare function createProgressTracker(totalSize: number, onUpdate: (percentage: number) => void): (current: number) => void;
|
|
136
|
-
|
|
137
|
-
export { type HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile };
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
import { MD5Result } from './md5-stream.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* File System Utilities for MD5 hashing
|
|
6
|
-
* Provides convenient utilities for hashing files through Node.js file system streams
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Options for file hashing operations
|
|
11
|
-
*/
|
|
12
|
-
interface HashFileOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Chunk size for reading file (default: 64KB)
|
|
15
|
-
*/
|
|
16
|
-
chunkSize?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Progress callback for tracking hashing progress
|
|
19
|
-
* @param current - Current position in bytes
|
|
20
|
-
*/
|
|
21
|
-
onProgress?: (current: number) => void;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Hash a file by its path
|
|
25
|
-
* @param filePath - Path to the file to hash
|
|
26
|
-
* @param options - Optional configuration
|
|
27
|
-
* @returns Promise with MD5 result (digest and bytes processed)
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* import { hashFile } from 'pure-md5';
|
|
32
|
-
*
|
|
33
|
-
* const result = await hashFile('path/to/file.txt');
|
|
34
|
-
* console.log('MD5:', result.digest);
|
|
35
|
-
* console.log('Bytes:', result.bytesProcessed);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
declare function hashFile(filePath: string, options?: HashFileOptions): Promise<MD5Result>;
|
|
39
|
-
/**
|
|
40
|
-
* Hash data from an existing readable stream
|
|
41
|
-
* @param readStream - Readable stream to hash
|
|
42
|
-
* @param options - Optional configuration
|
|
43
|
-
* @returns Promise with MD5 result (digest and bytes processed)
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { createReadStream } from 'fs';
|
|
48
|
-
* import { hashFileStream } from 'pure-md5';
|
|
49
|
-
*
|
|
50
|
-
* const stream = createReadStream('path/to/file.txt');
|
|
51
|
-
* const result = await hashFileStream(stream);
|
|
52
|
-
* console.log('MD5:', result.digest);
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
declare function hashFileStream(readStream: Readable, options?: {
|
|
56
|
-
onProgress?: (current: number) => void;
|
|
57
|
-
totalSize?: number;
|
|
58
|
-
}): Promise<MD5Result>;
|
|
59
|
-
/**
|
|
60
|
-
* Hash a file and return only the hex digest
|
|
61
|
-
* @param filePath - Path to the file to hash
|
|
62
|
-
* @param options - Optional configuration
|
|
63
|
-
* @returns Promise with MD5 hex digest string
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* import { hashFileDigest } from 'pure-md5';
|
|
68
|
-
*
|
|
69
|
-
* const digest = await hashFileDigest('path/to/file.txt');
|
|
70
|
-
* console.log('MD5:', digest);
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
declare function hashFileDigest(filePath: string, options?: HashFileOptions): Promise<string>;
|
|
74
|
-
/**
|
|
75
|
-
* Hash a file stream and return only the hex digest
|
|
76
|
-
* @param readStream - Readable stream to hash
|
|
77
|
-
* @param options - Optional configuration
|
|
78
|
-
* @returns Promise with MD5 hex digest string
|
|
79
|
-
*/
|
|
80
|
-
declare function hashFileStreamDigest(readStream: Readable, options?: {
|
|
81
|
-
onProgress?: (current: number) => void;
|
|
82
|
-
totalSize?: number;
|
|
83
|
-
}): Promise<string>;
|
|
84
|
-
/**
|
|
85
|
-
* Verify file integrity by comparing MD5 hash
|
|
86
|
-
* @param filePath - Path to the file to verify
|
|
87
|
-
* @param expectedDigest - Expected MD5 hex digest
|
|
88
|
-
* @param options - Optional configuration
|
|
89
|
-
* @returns Promise with verification result
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```ts
|
|
93
|
-
* import { verifyFile } from 'pure-md5';
|
|
94
|
-
*
|
|
95
|
-
* const isVerified = await verifyFile(
|
|
96
|
-
* 'path/to/file.txt',
|
|
97
|
-
* '5d41402abc4b2a76b9719d911017c592'
|
|
98
|
-
* );
|
|
99
|
-
* console.log('Verified:', isVerified);
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare function verifyFile(filePath: string, expectedDigest: string, options?: HashFileOptions): Promise<boolean>;
|
|
103
|
-
/**
|
|
104
|
-
* Get MD5 hash of a file synchronously (not recommended for large files)
|
|
105
|
-
* @param filePath - Path to the file to hash
|
|
106
|
-
* @returns MD5 hex digest string
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* import { hashFileSync } from 'pure-md5';
|
|
111
|
-
*
|
|
112
|
-
* const digest = hashFileSync('path/to/file.txt');
|
|
113
|
-
* console.log('MD5:', digest);
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
declare function hashFileSync(filePath: string): string;
|
|
117
|
-
/**
|
|
118
|
-
* Utility to create a progress tracker for file hashing
|
|
119
|
-
* @param totalSize - Total size of the file being hashed
|
|
120
|
-
* @param onUpdate - Callback with progress percentage (0-100)
|
|
121
|
-
* @returns Progress callback function
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* import { hashFile, createProgressTracker } from 'pure-md5';
|
|
126
|
-
*
|
|
127
|
-
* const totalSize = 1024 * 1024 * 100; // 100MB
|
|
128
|
-
* const progress = createProgressTracker(totalSize, (percent) => {
|
|
129
|
-
* console.log(`Progress: ${percent.toFixed(1)}%`);
|
|
130
|
-
* });
|
|
131
|
-
*
|
|
132
|
-
* const result = await hashFile('large-file.bin', { onProgress: progress });
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
declare function createProgressTracker(totalSize: number, onUpdate: (percentage: number) => void): (current: number) => void;
|
|
136
|
-
|
|
137
|
-
export { type HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile };
|
package/dist/stream/fs-utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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'../chunk-Z4JB6DTM.js';import'../chunk-MIU3X4SB.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
|
package/dist/stream/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var stream=require('stream'),D=require('fs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var D__default=/*#__PURE__*/_interopDefault(D);function U(o,r){return o+r&4294967295}var d=U;function T(o,r,a,e,t){let s=t||d;return r=s(s(r,o),s(a,e)),r}function $(o,r,a,e){var s=(e||d)(o<<r|o>>>32-r,a);return s}function R(o,r,a,e,t,s,n){return r=T(o,r,e,s,n),$(r,t,a,n)}function B(o,r,a,e,t,s,n,i){return R(a&e|~a&t,r,a,s,n,i,o)}function F(o,r,a,e,t,s,n,i){return R(a&t|e&~t,r,a,s,n,i,o)}function A(o,r,a,e,t,s,n,i){return R(a^e^t,r,a,s,n,i,o)}function L(o,r,a,e,t,s,n,i){return R(e^(a|~t),r,a,s,n,i,o)}function j(o,r,a){typeof a>"u"&&(a=d);let e=o[0],t=o[1],s=o[2],n=o[3],i=B.bind(null,a);e=i(e,t,s,n,r[0],7,-680876936),n=i(n,e,t,s,r[1],12,-389564586),s=i(s,n,e,t,r[2],17,606105819),t=i(t,s,n,e,r[3],22,-1044525330),e=i(e,t,s,n,r[4],7,-176418897),n=i(n,e,t,s,r[5],12,1200080426),s=i(s,n,e,t,r[6],17,-1473231341),t=i(t,s,n,e,r[7],22,-45705983),e=i(e,t,s,n,r[8],7,1770035416),n=i(n,e,t,s,r[9],12,-1958414417),s=i(s,n,e,t,r[10],17,-42063),t=i(t,s,n,e,r[11],22,-1990404162),e=i(e,t,s,n,r[12],7,1804603682),n=i(n,e,t,s,r[13],12,-40341101),s=i(s,n,e,t,r[14],17,-1502002290),t=i(t,s,n,e,r[15],22,1236535329);let u=F.bind(null,a);e=u(e,t,s,n,r[1],5,-165796510),n=u(n,e,t,s,r[6],9,-1069501632),s=u(s,n,e,t,r[11],14,643717713),t=u(t,s,n,e,r[0],20,-373897302),e=u(e,t,s,n,r[5],5,-701558691),n=u(n,e,t,s,r[10],9,38016083),s=u(s,n,e,t,r[15],14,-660478335),t=u(t,s,n,e,r[4],20,-405537848),e=u(e,t,s,n,r[9],5,568446438),n=u(n,e,t,s,r[14],9,-1019803690),s=u(s,n,e,t,r[3],14,-187363961),t=u(t,s,n,e,r[8],20,1163531501),e=u(e,t,s,n,r[13],5,-1444681467),n=u(n,e,t,s,r[2],9,-51403784),s=u(s,n,e,t,r[7],14,1735328473),t=u(t,s,n,e,r[12],20,-1926607734);let f=A.bind(null,a);e=f(e,t,s,n,r[5],4,-378558),n=f(n,e,t,s,r[8],11,-2022574463),s=f(s,n,e,t,r[11],16,1839030562),t=f(t,s,n,e,r[14],23,-35309556),e=f(e,t,s,n,r[1],4,-1530992060),n=f(n,e,t,s,r[4],11,1272893353),s=f(s,n,e,t,r[7],16,-155497632),t=f(t,s,n,e,r[10],23,-1094730640),e=f(e,t,s,n,r[13],4,681279174),n=f(n,e,t,s,r[0],11,-358537222),s=f(s,n,e,t,r[3],16,-722521979),t=f(t,s,n,e,r[6],23,76029189),e=f(e,t,s,n,r[9],4,-640364487),n=f(n,e,t,s,r[12],11,-421815835),s=f(s,n,e,t,r[15],16,530742520),t=f(t,s,n,e,r[2],23,-995338651);let m=L.bind(null,a);e=m(e,t,s,n,r[0],6,-198630844),n=m(n,e,t,s,r[7],10,1126891415),s=m(s,n,e,t,r[14],15,-1416354905),t=m(t,s,n,e,r[5],21,-57434055),e=m(e,t,s,n,r[12],6,1700485571),n=m(n,e,t,s,r[3],10,-1894986606),s=m(s,n,e,t,r[10],15,-1051523),t=m(t,s,n,e,r[1],21,-2054922799),e=m(e,t,s,n,r[8],6,1873313359),n=m(n,e,t,s,r[15],10,-30611744),s=m(s,n,e,t,r[6],15,-1560198380),t=m(t,s,n,e,r[13],21,1309151649),e=m(e,t,s,n,r[4],6,-145523070),n=m(n,e,t,s,r[11],10,-1120210379),s=m(s,n,e,t,r[2],15,718787259),t=m(t,s,n,e,r[9],21,-343485551),o[0]=a(e,o[0]),o[1]=a(t,o[1]),o[2]=a(s,o[2]),o[3]=a(n,o[3]);}var b=j;var z="0123456789abcdef".split(""),S=z;function H(o){let r="";for(let a=0;a<4;a++)r+=S[o>>a*8+4&15]+S[o>>a*8&15];return r}function _(o){let r=o.length,a=new Array(r);for(let e=0;e<r;e++)a[e]=H(o[e]);return a.join("")}var g=_;var M=class o extends stream.Transform{constructor(a){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=a?.add32||d,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(a,e,t){try{let s=a,n=s.length;if(n===0){t();return}if(this.state.bufferLength>0){let f=this.state.bufferLength,m=64-f,l=Math.min(n,m);for(let c=0;c<l;c++)this.buffer[f+c]=s[c];if(this.state.bufferLength+=l,this.state.bufferLength===64&&this._processBufferBlock(),l===n){t();return}let h=n-l;for(let c=0;c<h;c++)s[c]=s[l+c];let y=Buffer.alloc(h);for(let c=0;c<h;c++)y[c]=s[c];s=y;}let i=Math.floor(s.length/64);for(let f=0;f<i;f++){let m=f*64,l=[];for(let h=0;h<16;h++){let y=m+h*4;l[h]=s[y]+(s[y+1]<<8)+(s[y+2]<<16)+(s[y+3]<<24);}b(this.state.state,l,this.add32),this.state.bytesProcessed+=64;}let u=s.length%64;if(u>0){this.buffer.length<u&&(this.buffer=new Uint8Array(u),this.state.buffer=this.buffer);for(let f=0;f<u;f++)this.buffer[f]=s[i*64+f];this.state.bufferLength=u;}t();}catch(s){t(s);}}_processBufferBlock(){let a=this.state.buffer,e=[];for(let t=0;t<16;t++){let s=t*4;e[t]=a[s]+(a[s+1]<<8)+(a[s+2]<<16)+(a[s+3]<<24);}b(this.state.state,e,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(a){try{let{state:e,bufferLength:t,buffer:s}=this.state,n=new Array(16).fill(0);for(let u=0;u<t;u++)n[u>>2]|=(s[u]&255)<<(u%4<<3);if(n[t>>2]|=128<<(t%4<<3),t>55){b(e,n,this.add32);for(let u=0;u<16;u++)n[u]=0;}n[14]=(this.state.bytesProcessed+t)*8,n[15]=0,b(e,n,this.add32);let i=g(e);this.emit("md5",{digest:i,bytesProcessed:this.state.bytesProcessed+t}),a();}catch(e){a(e);}}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(a,e){let t=new o(e),s=x.call(t,a);return {stream:t,result:s}}};function w(o){return new M(o)}async function x(o){return new Promise((r,a)=>{let e=[];o.pipe(this).on("md5",t=>{e.push(t);}).on("error",a).on("finish",()=>{r(e[0]);});})}function O(o,r){let a=new M(r),e=x.call(a,o);return {stream:a,result:e}}function I(o,r){let a=o.length,e=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=a;t+=64){let i=q(o,t-64);b(e,i,r);}let s=a-t+64,n=new Array(16).fill(0);for(let i=0;i<s;i++)n[i>>2]|=(o[a-s+i]&255)<<(i%4<<3);if(n[s>>2]|=128<<(s%4<<3),s>55){b(e,n,r);for(let i=0;i<16;i++)n[i]=0;}return n[14]=a*8,n[15]=0,b(e,n,r),e}function q(o,r){let a=[];for(let e=0;e<64;e+=4)a[e>>2]=(o[r+e]||0)+((o[r+e+1]||0)<<8)+((o[r+e+2]||0)<<16)+((o[r+e+3]||0)<<24);return a}var C=I;function E(o){return g(C(o,d))}async function P(o,r={}){if(typeof o!="string"||o.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!D__default.default.existsSync(o))throw new Error(`File not found: ${o}`);let a;try{a=D__default.default.statSync(o);}catch(t){throw new Error(`Failed to access file ${o}: ${t.message}`)}if(!a.isFile())throw new Error(`Path is not a file: ${o}`);let e=D__default.default.createReadStream(o,{highWaterMark:r.chunkSize||64*1024});try{return await v(e,{onProgress:r.onProgress,totalSize:a.size})}finally{e.destroy();}}async function v(o,r={}){if(!o||typeof o.on!="function")throw new Error("Invalid readable stream: stream must have event listener support");let a=w(),e=0;return r.onProgress&&o.on("data",t=>{e+=t.length,r.onProgress?.(e);}),o.on("error",t=>{a.destroy(t);}),o.on("end",()=>{a.end();}),new Promise((t,s)=>{a.on("md5",n=>{t(n);}).on("error",n=>{s(n);}),o.pipe(a);})}async function G(o,r={}){return (await P(o,r)).digest}async function J(o,r={}){return (await v(o,r)).digest}async function K(o,r,a={}){return (await P(o,a)).digest.toLowerCase()===r.toLowerCase()}function N(o){if(typeof o!="string"||o.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!D__default.default.existsSync(o))throw new Error(`File not found: ${o}`);let r;try{r=D__default.default.statSync(o);}catch(e){throw new Error(`Failed to access file ${o}: ${e.message}`)}if(!r.isFile())throw new Error(`Path is not a file: ${o}`);let a;try{a=D__default.default.readFileSync(o);}catch(e){throw new Error(`Failed to read file ${o}: ${e.message}`)}return E(a)}function Q(o,r){let a=0;return e=>{if(o>0){let t=Math.min(100,e/o*100);Math.floor(t)!==Math.floor(a)&&(r(t),a=t);}}}var V=[1732584193,-271733879,-1732584194,271733878],p=class o{constructor(r,a={}){this.result=null;this.resultResolver=null;this.consumed=false;this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.sourceStream=r,this.state={state:[...V],bytesProcessed:0,bufferLength:0,buffer:this.buffer},this.add32=a.add32||d,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:r,writable:a}=new TransformStream({transform:async(e,t)=>{await this.processChunk(e),t.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});}),r.getReader()}async processChunk(r){let a;r instanceof Blob?a=new Uint8Array(await r.arrayBuffer()):r instanceof ArrayBuffer?a=new Uint8Array(r):a=r;let e=a.length;if(e===0)return;if(this.state.bufferLength>0){let n=this.state.bufferLength,i=64-n,u=Math.min(e,i);for(let l=0;l<u;l++)this.buffer[n+l]=a[l];if(this.state.bufferLength+=u,this.state.bufferLength===64&&this._processBufferBlock(),u===e)return;let f=e-u,m=new Uint8Array(f);for(let l=0;l<f;l++)m[l]=a[u+l];a=m;}let t=Math.floor(a.length/64);for(let n=0;n<t;n++){let i=n*64,u=[];for(let f=0;f<16;f++){let m=i+f*4;u[f]=a[m]+(a[m+1]<<8)+(a[m+2]<<16)+(a[m+3]<<24);}b(this.state.state,u,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 n=0;n<s;n++)this.buffer[n]=a[t+n];this.state.bufferLength=s;}}_processBufferBlock(){let r=this.state.buffer,a=[];for(let e=0;e<16;e++){let t=e*4;a[e]=r[t]+(r[t+1]<<8)+(r[t+2]<<16)+(r[t+3]<<24);}b(this.state.state,a,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}finalize(){let{state:r,bufferLength:a,buffer:e}=this.state,t=new Array(16).fill(0);for(let n=0;n<a;n++)t[n>>2]|=(e[n]&255)<<(n%4<<3);if(t[a>>2]|=128<<(a%4<<3),a>55){b(r,t,this.add32);for(let n=0;n<16;n++)t[n]=0;}t[14]=(this.state.bytesProcessed+a)*8,t[15]=0,b(r,t,this.add32);let s=g(r);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(r,a){let e=new o(r,a),t=e.getReader();return new Promise((s,n)=>{let i=0;t.read().then(function u({done:f,value:m}){if(f){s(e.getResult());return}i+=m.length,t.read().then(u);}).catch(n);})}static hashFile(r,a){let e=r.stream();return o.hash(e,a)}static hashBlob(r,a){return new Promise((e,t)=>{let s=new FileReader;s.onload=n=>{try{let i=n.target?.result,u=new ReadableStream({start(f){f.enqueue(new Uint8Array(i)),f.close();}});e(o.hash(u,a));}catch(i){t(i);}},s.onerror=()=>t(s.error),s.readAsArrayBuffer(r);})}};function X(o,r){return new p(o,r)}async function Y(o,r){let a=o.getReader(),e=new p(o,r),t=0;for(;;){let{done:s,value:n}=await a.read();if(s)break;n&&(t+=n.length);}return e.getResult()}async function Z(o,r){return p.hashFile(o,r)}async function k(o,r){return p.hashBlob(o,r)}async function ee(o,r){let a=o.getReader(),e=new p(o,r),t=0;for(;;){let{done:s,value:n}=await a.read();if(s)break;n&&(t+=n.length);}return e.getResult()}Object.defineProperty(M,"fromStream",{value:O,writable:false,configurable:false});exports.MD5ReadableStream=p;exports.MD5Stream=M;exports.consumeWithMD5=ee;exports.createMD5ReadableStream=X;exports.createMD5Stream=w;exports.createProgressTracker=Q;exports.fromStream=O;exports.hashBlob=k;exports.hashFile=P;exports.hashFileDigest=G;exports.hashFileStream=v;exports.hashFileStreamDigest=J;exports.hashFileSync=N;exports.hashFileWHATWG=Z;exports.hashReadableStream=Y;exports.pipeThroughMD5=x;exports.verifyFile=K;
|
package/dist/stream/index.d.cts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { MD5Result, MD5Stream, createMD5Stream, fromStream, pipeThroughMD5 } from './md5-stream.cjs';
|
|
2
|
-
export { HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile } from './fs-utils.cjs';
|
|
3
|
-
export { MD5ReadableStream, MD5ReadableStreamOptions, consumeWithMD5, createMD5ReadableStream, hashBlob, hashFile as hashFileWHATWG, hashReadableStream } from './whatwg-stream.cjs';
|
|
4
|
-
import 'stream';
|
package/dist/stream/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { MD5Result, MD5Stream, createMD5Stream, fromStream, pipeThroughMD5 } from './md5-stream.js';
|
|
2
|
-
export { HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile } from './fs-utils.js';
|
|
3
|
-
export { MD5ReadableStream, MD5ReadableStreamOptions, consumeWithMD5, createMD5ReadableStream, hashBlob, hashFile as hashFileWHATWG, hashReadableStream } from './whatwg-stream.js';
|
|
4
|
-
import 'stream';
|
package/dist/stream/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import'../chunk-374HUUY2.js';export{a as MD5ReadableStream,f as consumeWithMD5,b as createMD5ReadableStream,e as hashBlob,d as hashFileWHATWG,c as hashReadableStream}from'../chunk-BEGGPFEE.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'../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';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var stream=require('stream'),M=require('fs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var M__default=/*#__PURE__*/_interopDefault(M);function E(o,r){return o+r&4294967295}var d=E;function U(o,r,a,e,t){let s=t||d;return r=s(s(r,o),s(a,e)),r}function T(o,r,a,e){var s=(e||d)(o<<r|o>>>32-r,a);return s}function D(o,r,a,e,t,s,n){return r=U(o,r,e,s,n),T(r,t,a,n)}function B(o,r,a,e,t,s,n,i){return D(a&e|~a&t,r,a,s,n,i,o)}function F(o,r,a,e,t,s,n,i){return D(a&t|e&~t,r,a,s,n,i,o)}function A(o,r,a,e,t,s,n,i){return D(a^e^t,r,a,s,n,i,o)}function L(o,r,a,e,t,s,n,i){return D(e^(a|~t),r,a,s,n,i,o)}function $(o,r,a){typeof a>"u"&&(a=d);let e=o[0],t=o[1],s=o[2],n=o[3],i=B.bind(null,a);e=i(e,t,s,n,r[0],7,-680876936),n=i(n,e,t,s,r[1],12,-389564586),s=i(s,n,e,t,r[2],17,606105819),t=i(t,s,n,e,r[3],22,-1044525330),e=i(e,t,s,n,r[4],7,-176418897),n=i(n,e,t,s,r[5],12,1200080426),s=i(s,n,e,t,r[6],17,-1473231341),t=i(t,s,n,e,r[7],22,-45705983),e=i(e,t,s,n,r[8],7,1770035416),n=i(n,e,t,s,r[9],12,-1958414417),s=i(s,n,e,t,r[10],17,-42063),t=i(t,s,n,e,r[11],22,-1990404162),e=i(e,t,s,n,r[12],7,1804603682),n=i(n,e,t,s,r[13],12,-40341101),s=i(s,n,e,t,r[14],17,-1502002290),t=i(t,s,n,e,r[15],22,1236535329);let u=F.bind(null,a);e=u(e,t,s,n,r[1],5,-165796510),n=u(n,e,t,s,r[6],9,-1069501632),s=u(s,n,e,t,r[11],14,643717713),t=u(t,s,n,e,r[0],20,-373897302),e=u(e,t,s,n,r[5],5,-701558691),n=u(n,e,t,s,r[10],9,38016083),s=u(s,n,e,t,r[15],14,-660478335),t=u(t,s,n,e,r[4],20,-405537848),e=u(e,t,s,n,r[9],5,568446438),n=u(n,e,t,s,r[14],9,-1019803690),s=u(s,n,e,t,r[3],14,-187363961),t=u(t,s,n,e,r[8],20,1163531501),e=u(e,t,s,n,r[13],5,-1444681467),n=u(n,e,t,s,r[2],9,-51403784),s=u(s,n,e,t,r[7],14,1735328473),t=u(t,s,n,e,r[12],20,-1926607734);let f=A.bind(null,a);e=f(e,t,s,n,r[5],4,-378558),n=f(n,e,t,s,r[8],11,-2022574463),s=f(s,n,e,t,r[11],16,1839030562),t=f(t,s,n,e,r[14],23,-35309556),e=f(e,t,s,n,r[1],4,-1530992060),n=f(n,e,t,s,r[4],11,1272893353),s=f(s,n,e,t,r[7],16,-155497632),t=f(t,s,n,e,r[10],23,-1094730640),e=f(e,t,s,n,r[13],4,681279174),n=f(n,e,t,s,r[0],11,-358537222),s=f(s,n,e,t,r[3],16,-722521979),t=f(t,s,n,e,r[6],23,76029189),e=f(e,t,s,n,r[9],4,-640364487),n=f(n,e,t,s,r[12],11,-421815835),s=f(s,n,e,t,r[15],16,530742520),t=f(t,s,n,e,r[2],23,-995338651);let m=L.bind(null,a);e=m(e,t,s,n,r[0],6,-198630844),n=m(n,e,t,s,r[7],10,1126891415),s=m(s,n,e,t,r[14],15,-1416354905),t=m(t,s,n,e,r[5],21,-57434055),e=m(e,t,s,n,r[12],6,1700485571),n=m(n,e,t,s,r[3],10,-1894986606),s=m(s,n,e,t,r[10],15,-1051523),t=m(t,s,n,e,r[1],21,-2054922799),e=m(e,t,s,n,r[8],6,1873313359),n=m(n,e,t,s,r[15],10,-30611744),s=m(s,n,e,t,r[6],15,-1560198380),t=m(t,s,n,e,r[13],21,1309151649),e=m(e,t,s,n,r[4],6,-145523070),n=m(n,e,t,s,r[11],10,-1120210379),s=m(s,n,e,t,r[2],15,718787259),t=m(t,s,n,e,r[9],21,-343485551),o[0]=a(e,o[0]),o[1]=a(t,o[1]),o[2]=a(s,o[2]),o[3]=a(n,o[3]);}var b=$;var j="0123456789abcdef".split(""),S=j;function z(o){let r="";for(let a=0;a<4;a++)r+=S[o>>a*8+4&15]+S[o>>a*8&15];return r}function H(o){let r=o.length,a=new Array(r);for(let e=0;e<r;e++)a[e]=z(o[e]);return a.join("")}var g=H;var R=class o extends stream.Transform{constructor(a){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=a?.add32||d,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(a,e,t){try{let s=a,n=s.length;if(n===0){t();return}if(this.state.bufferLength>0){let f=this.state.bufferLength,m=64-f,l=Math.min(n,m);for(let c=0;c<l;c++)this.buffer[f+c]=s[c];if(this.state.bufferLength+=l,this.state.bufferLength===64&&this._processBufferBlock(),l===n){t();return}let h=n-l;for(let c=0;c<h;c++)s[c]=s[l+c];let y=Buffer.alloc(h);for(let c=0;c<h;c++)y[c]=s[c];s=y;}let i=Math.floor(s.length/64);for(let f=0;f<i;f++){let m=f*64,l=[];for(let h=0;h<16;h++){let y=m+h*4;l[h]=s[y]+(s[y+1]<<8)+(s[y+2]<<16)+(s[y+3]<<24);}b(this.state.state,l,this.add32),this.state.bytesProcessed+=64;}let u=s.length%64;if(u>0){this.buffer.length<u&&(this.buffer=new Uint8Array(u),this.state.buffer=this.buffer);for(let f=0;f<u;f++)this.buffer[f]=s[i*64+f];this.state.bufferLength=u;}t();}catch(s){t(s);}}_processBufferBlock(){let a=this.state.buffer,e=[];for(let t=0;t<16;t++){let s=t*4;e[t]=a[s]+(a[s+1]<<8)+(a[s+2]<<16)+(a[s+3]<<24);}b(this.state.state,e,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(a){try{let{state:e,bufferLength:t,buffer:s}=this.state,n=new Array(16).fill(0);for(let u=0;u<t;u++)n[u>>2]|=(s[u]&255)<<(u%4<<3);if(n[t>>2]|=128<<(t%4<<3),t>55){b(e,n,this.add32);for(let u=0;u<16;u++)n[u]=0;}n[14]=(this.state.bytesProcessed+t)*8,n[15]=0,b(e,n,this.add32);let i=g(e);this.emit("md5",{digest:i,bytesProcessed:this.state.bytesProcessed+t}),a();}catch(e){a(e);}}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(a,e){let t=new o(e),s=x.call(t,a);return {stream:t,result:s}}};function w(o){return new R(o)}async function x(o){return new Promise((r,a)=>{let e=[];o.pipe(this).on("md5",t=>{e.push(t);}).on("error",a).on("finish",()=>{r(e[0]);});})}function W(o,r){let a=new R(r),e=x.call(a,o);return {stream:a,result:e}}function I(o,r){let a=o.length,e=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=a;t+=64){let i=q(o,t-64);b(e,i,r);}let s=a-t+64,n=new Array(16).fill(0);for(let i=0;i<s;i++)n[i>>2]|=(o[a-s+i]&255)<<(i%4<<3);if(n[s>>2]|=128<<(s%4<<3),s>55){b(e,n,r);for(let i=0;i<16;i++)n[i]=0;}return n[14]=a*8,n[15]=0,b(e,n,r),e}function q(o,r){let a=[];for(let e=0;e<64;e+=4)a[e>>2]=(o[r+e]||0)+((o[r+e+1]||0)<<8)+((o[r+e+2]||0)<<16)+((o[r+e+3]||0)<<24);return a}var O=I;function C(o){return g(O(o,d))}async function P(o,r={}){if(typeof o!="string"||o.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!M__default.default.existsSync(o))throw new Error(`File not found: ${o}`);let a;try{a=M__default.default.statSync(o);}catch(t){throw new Error(`Failed to access file ${o}: ${t.message}`)}if(!a.isFile())throw new Error(`Path is not a file: ${o}`);let e=M__default.default.createReadStream(o,{highWaterMark:r.chunkSize||64*1024});try{return await v(e,{onProgress:r.onProgress,totalSize:a.size})}finally{e.destroy();}}async function v(o,r={}){if(!o||typeof o.on!="function")throw new Error("Invalid readable stream: stream must have event listener support");let a=w(),e=0;return r.onProgress&&o.on("data",t=>{e+=t.length,r.onProgress?.(e);}),o.on("error",t=>{a.destroy(t);}),o.on("end",()=>{a.end();}),new Promise((t,s)=>{a.on("md5",n=>{t(n);}).on("error",n=>{s(n);}),o.pipe(a);})}async function G(o,r={}){return (await P(o,r)).digest}async function J(o,r={}){return (await v(o,r)).digest}async function K(o,r,a={}){return (await P(o,a)).digest.toLowerCase()===r.toLowerCase()}function N(o){if(typeof o!="string"||o.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!M__default.default.existsSync(o))throw new Error(`File not found: ${o}`);let r;try{r=M__default.default.statSync(o);}catch(e){throw new Error(`Failed to access file ${o}: ${e.message}`)}if(!r.isFile())throw new Error(`Path is not a file: ${o}`);let a;try{a=M__default.default.readFileSync(o);}catch(e){throw new Error(`Failed to read file ${o}: ${e.message}`)}return C(a)}function Q(o,r){let a=0;return e=>{if(o>0){let t=Math.min(100,e/o*100);Math.floor(t)!==Math.floor(a)&&(r(t),a=t);}}}var V=[1732584193,-271733879,-1732584194,271733878],p=class o{constructor(r,a={}){this.result=null;this.resultResolver=null;this.consumed=false;this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.sourceStream=r,this.state={state:[...V],bytesProcessed:0,bufferLength:0,buffer:this.buffer},this.add32=a.add32||d,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:r,writable:a}=new TransformStream({transform:async(e,t)=>{await this.processChunk(e),t.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});}),r.getReader()}async processChunk(r){let a;r instanceof Blob?a=new Uint8Array(await r.arrayBuffer()):r instanceof ArrayBuffer?a=new Uint8Array(r):a=r;let e=a.length;if(e===0)return;if(this.state.bufferLength>0){let n=this.state.bufferLength,i=64-n,u=Math.min(e,i);for(let l=0;l<u;l++)this.buffer[n+l]=a[l];if(this.state.bufferLength+=u,this.state.bufferLength===64&&this._processBufferBlock(),u===e)return;let f=e-u,m=new Uint8Array(f);for(let l=0;l<f;l++)m[l]=a[u+l];a=m;}let t=Math.floor(a.length/64);for(let n=0;n<t;n++){let i=n*64,u=[];for(let f=0;f<16;f++){let m=i+f*4;u[f]=a[m]+(a[m+1]<<8)+(a[m+2]<<16)+(a[m+3]<<24);}b(this.state.state,u,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 n=0;n<s;n++)this.buffer[n]=a[t+n];this.state.bufferLength=s;}}_processBufferBlock(){let r=this.state.buffer,a=[];for(let e=0;e<16;e++){let t=e*4;a[e]=r[t]+(r[t+1]<<8)+(r[t+2]<<16)+(r[t+3]<<24);}b(this.state.state,a,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}finalize(){let{state:r,bufferLength:a,buffer:e}=this.state,t=new Array(16).fill(0);for(let n=0;n<a;n++)t[n>>2]|=(e[n]&255)<<(n%4<<3);if(t[a>>2]|=128<<(a%4<<3),a>55){b(r,t,this.add32);for(let n=0;n<16;n++)t[n]=0;}t[14]=(this.state.bytesProcessed+a)*8,t[15]=0,b(r,t,this.add32);let s=g(r);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(r,a){let e=new o(r,a),t=e.getReader();return new Promise((s,n)=>{let i=0;t.read().then(function u({done:f,value:m}){if(f){s(e.getResult());return}i+=m.length,t.read().then(u);}).catch(n);})}static hashFile(r,a){let e=r.stream();return o.hash(e,a)}static hashBlob(r,a){return new Promise((e,t)=>{let s=new FileReader;s.onload=n=>{try{let i=n.target?.result,u=new ReadableStream({start(f){f.enqueue(new Uint8Array(i)),f.close();}});e(o.hash(u,a));}catch(i){t(i);}},s.onerror=()=>t(s.error),s.readAsArrayBuffer(r);})}};function X(o,r){return new p(o,r)}async function Y(o,r){let a=o.getReader(),e=new p(o,r),t=0;for(;;){let{done:s,value:n}=await a.read();if(s)break;n&&(t+=n.length);}return e.getResult()}async function Z(o,r){return p.hashFile(o,r)}async function k(o,r){return p.hashBlob(o,r)}async function ee(o,r){let a=o.getReader(),e=new p(o,r),t=0;for(;;){let{done:s,value:n}=await a.read();if(s)break;n&&(t+=n.length);}return e.getResult()}exports.MD5ReadableStream=p;exports.MD5Stream=R;exports.consumeWithMD5=ee;exports.createMD5ReadableStream=X;exports.createMD5Stream=w;exports.createProgressTracker=Q;exports.fromStream=W;exports.hashBlob=k;exports.hashFile=P;exports.hashFileDigest=G;exports.hashFileStream=v;exports.hashFileStreamDigest=J;exports.hashFileSync=N;exports.hashFileWHATWG=Z;exports.hashReadableStream=Y;exports.pipeThroughMD5=x;exports.verifyFile=K;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { MD5Result, MD5Stream, createMD5Stream, fromStream, pipeThroughMD5 } from '../md5-stream.cjs';
|
|
2
|
-
export { HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile } from '../fs-utils.cjs';
|
|
3
|
-
export { MD5ReadableStream, MD5ReadableStreamOptions, consumeWithMD5, createMD5ReadableStream, hashBlob, hashFile as hashFileWHATWG, hashReadableStream } from '../whatwg-stream.cjs';
|
|
4
|
-
import 'stream';
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { MD5Result, MD5Stream, createMD5Stream, fromStream, pipeThroughMD5 } from '../md5-stream.js';
|
|
2
|
-
export { HashFileOptions, createProgressTracker, hashFile, hashFileDigest, hashFileStream, hashFileStreamDigest, hashFileSync, verifyFile } from '../fs-utils.js';
|
|
3
|
-
export { MD5ReadableStream, MD5ReadableStreamOptions, consumeWithMD5, createMD5ReadableStream, hashBlob, hashFile as hashFileWHATWG, hashReadableStream } from '../whatwg-stream.js';
|
|
4
|
-
import 'stream';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{a as MD5ReadableStream,f as consumeWithMD5,b as createMD5ReadableStream,e as hashBlob,d as hashFileWHATWG,c as hashReadableStream}from'../../chunk-BEGGPFEE.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'../../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';
|