@datastream/digest
Advanced tools
+6
-2
| // Copyright 2026 will Farrell, and datastream contributors. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { StreamOptions, StreamResult } from "@datastream/core"; | ||
| import type { | ||
| DatastreamPassThrough, | ||
| StreamOptions, | ||
| StreamResult, | ||
| } from "@datastream/core"; | ||
@@ -13,3 +17,3 @@ export type DigestAlgorithm = | ||
| type DigestStreamResult = unknown & { | ||
| type DigestStreamResult = DatastreamPassThrough & { | ||
| result: () => StreamResult<string>; | ||
@@ -16,0 +20,0 @@ }; |
+3
-0
@@ -17,2 +17,5 @@ import { createPassThroughStream } from "@datastream/core"; | ||
| const digestStream = async ({ algorithm, resultKey }, streamOptions = {}) => { | ||
| if (!algorithms[algorithm]) { | ||
| throw new Error(`Unsupported algorithm: ${algorithm}`); | ||
| } | ||
| const hash = await algorithms[algorithm](); | ||
@@ -19,0 +22,0 @@ const passThrough = (chunk) => { |
| { | ||
| "version": 3, | ||
| "sources": ["index.web.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createPassThroughStream } from \"@datastream/core\";\nimport {\n\tcreateSHA3,\n\tcreateSHA256,\n\tcreateSHA384,\n\tcreateSHA512,\n} from \"hash-wasm\";\n\nconst algorithms = {\n\t\"SHA2-256\": createSHA256,\n\t\"SHA2-384\": createSHA384,\n\t\"SHA2-512\": createSHA512,\n\t\"SHA3-256\": () => createSHA3(256),\n\t\"SHA3-384\": () => createSHA3(384),\n\t\"SHA3-512\": () => createSHA3(512),\n};\n\nexport const digestStream = async (\n\t{ algorithm, resultKey },\n\tstreamOptions = {},\n) => {\n\tconst hash = await algorithms[algorithm]();\n\tconst passThrough = (chunk) => {\n\t\thash.update(chunk);\n\t};\n\tconst stream = createPassThroughStream(passThrough, streamOptions);\n\tlet checksum;\n\tstream.result = () => {\n\t\tchecksum ??= hash.digest();\n\t\treturn {\n\t\t\tkey: resultKey ?? \"digest\",\n\t\t\tvalue: `${algorithm}:${checksum}`,\n\t\t};\n\t};\n\treturn stream;\n};\n\nexport default digestStream;\n"], | ||
| "mappings": "AAEA,SAAS,+BAA+B;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,MAAM,aAAa;AAAA,EAClB,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY,MAAM,WAAW,GAAG;AAAA,EAChC,YAAY,MAAM,WAAW,GAAG;AAAA,EAChC,YAAY,MAAM,WAAW,GAAG;AACjC;AAEO,MAAM,eAAe,OAC3B,EAAE,WAAW,UAAU,GACvB,gBAAgB,CAAC,MACb;AACJ,QAAM,OAAO,MAAM,WAAW,SAAS,EAAE;AACzC,QAAM,cAAc,CAAC,UAAU;AAC9B,SAAK,OAAO,KAAK;AAAA,EAClB;AACA,QAAM,SAAS,wBAAwB,aAAa,aAAa;AACjE,MAAI;AACJ,SAAO,SAAS,MAAM;AACrB,iBAAa,KAAK,OAAO;AACzB,WAAO;AAAA,MACN,KAAK,aAAa;AAAA,MAClB,OAAO,GAAG,SAAS,IAAI,QAAQ;AAAA,IAChC;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,oBAAQ;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createPassThroughStream } from \"@datastream/core\";\nimport {\n\tcreateSHA3,\n\tcreateSHA256,\n\tcreateSHA384,\n\tcreateSHA512,\n} from \"hash-wasm\";\n\nconst algorithms = {\n\t\"SHA2-256\": createSHA256,\n\t\"SHA2-384\": createSHA384,\n\t\"SHA2-512\": createSHA512,\n\t\"SHA3-256\": () => createSHA3(256),\n\t\"SHA3-384\": () => createSHA3(384),\n\t\"SHA3-512\": () => createSHA3(512),\n};\n\nexport const digestStream = async (\n\t{ algorithm, resultKey },\n\tstreamOptions = {},\n) => {\n\tif (!algorithms[algorithm]) {\n\t\tthrow new Error(`Unsupported algorithm: ${algorithm}`);\n\t}\n\tconst hash = await algorithms[algorithm]();\n\tconst passThrough = (chunk) => {\n\t\thash.update(chunk);\n\t};\n\tconst stream = createPassThroughStream(passThrough, streamOptions);\n\tlet checksum;\n\tstream.result = () => {\n\t\tchecksum ??= hash.digest();\n\t\treturn {\n\t\t\tkey: resultKey ?? \"digest\",\n\t\t\tvalue: `${algorithm}:${checksum}`,\n\t\t};\n\t};\n\treturn stream;\n};\n\nexport default digestStream;\n"], | ||
| "mappings": "AAEA,SAAS,+BAA+B;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,MAAM,aAAa;AAAA,EAClB,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY,MAAM,WAAW,GAAG;AAAA,EAChC,YAAY,MAAM,WAAW,GAAG;AAAA,EAChC,YAAY,MAAM,WAAW,GAAG;AACjC;AAEO,MAAM,eAAe,OAC3B,EAAE,WAAW,UAAU,GACvB,gBAAgB,CAAC,MACb;AACJ,MAAI,CAAC,WAAW,SAAS,GAAG;AAC3B,UAAM,IAAI,MAAM,0BAA0B,SAAS,EAAE;AAAA,EACtD;AACA,QAAM,OAAO,MAAM,WAAW,SAAS,EAAE;AACzC,QAAM,cAAc,CAAC,UAAU;AAC9B,SAAK,OAAO,KAAK;AAAA,EAClB;AACA,QAAM,SAAS,wBAAwB,aAAa,aAAa;AACjE,MAAI;AACJ,SAAO,SAAS,MAAM;AACrB,iBAAa,KAAK,OAAO;AACzB,WAAO;AAAA,MACN,KAAK,aAAa;AAAA,MAClB,OAAO,GAAG,SAAS,IAAI,QAAQ;AAAA,IAChC;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,oBAAQ;", | ||
| "names": [] | ||
| } |
+2
-2
| { | ||
| "name": "@datastream/digest", | ||
| "version": "0.3.0", | ||
| "version": "0.3.1", | ||
| "description": "Cryptographic hash digest pass-through streams", | ||
@@ -63,5 +63,5 @@ "type": "module", | ||
| "dependencies": { | ||
| "@datastream/core": "0.3.0", | ||
| "@datastream/core": "0.3.1", | ||
| "hash-wasm": "4.12.0" | ||
| } | ||
| } |
10954
2.96%92
8.24%+ Added
- Removed
Updated