@datastream/compress
Advanced tools
+23
-2
@@ -14,4 +14,25 @@ import { | ||
| }; | ||
| const brotliDecompressStream = (params, streamOptions = {}) => { | ||
| return createBrotliDecompress({ ...streamOptions, params }); | ||
| const brotliDecompressStream = (options = {}, streamOptions = {}) => { | ||
| const { maxOutputSize, ...params } = options; | ||
| const zlibOptions = Object.keys(params).length ? { ...streamOptions, params } : streamOptions; | ||
| const stream = createBrotliDecompress(zlibOptions); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const originalPush = stream.push.bind(stream); | ||
| stream.push = (chunk) => { | ||
| if (chunk !== null) { | ||
| outputSize += chunk.length; | ||
| if (outputSize > maxOutputSize) { | ||
| stream.destroy( | ||
| new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return false; | ||
| } | ||
| } | ||
| return originalPush(chunk); | ||
| }; | ||
| } | ||
| return stream; | ||
| }; | ||
@@ -18,0 +39,0 @@ var brotli_node_default = { |
| { | ||
| "version": 3, | ||
| "sources": ["brotli.node.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport {\n\tconstants,\n\tcreateBrotliCompress,\n\tcreateBrotliDecompress,\n} from \"node:zlib\";\n\n// quality: 0 - 11\nexport const brotliCompressStream = ({ quality } = {}, streamOptions = {}) => {\n\treturn createBrotliCompress({\n\t\t...streamOptions,\n\t\tparams: {\n\t\t\t[constants.BROTLI_PARAM_QUALITY]:\n\t\t\t\tquality ?? constants.BROTLI_DEFAULT_QUALITY,\n\t\t},\n\t});\n};\nexport const brotliDecompressStream = (params, streamOptions = {}) => {\n\treturn createBrotliDecompress({ ...streamOptions, params });\n};\n\nexport default {\n\tcompressStream: brotliCompressStream,\n\tdecompressStream: brotliDecompressStream,\n};\n"], | ||
| "mappings": "AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGA,MAAM,uBAAuB,CAAC,EAAE,QAAQ,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC7E,SAAO,qBAAqB;AAAA,IAC3B,GAAG;AAAA,IACH,QAAQ;AAAA,MACP,CAAC,UAAU,oBAAoB,GAC9B,WAAW,UAAU;AAAA,IACvB;AAAA,EACD,CAAC;AACF;AACO,MAAM,yBAAyB,CAAC,QAAQ,gBAAgB,CAAC,MAAM;AACrE,SAAO,uBAAuB,EAAE,GAAG,eAAe,OAAO,CAAC;AAC3D;AAEA,IAAO,sBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport {\n\tconstants,\n\tcreateBrotliCompress,\n\tcreateBrotliDecompress,\n} from \"node:zlib\";\n\n// quality: 0 - 11\nexport const brotliCompressStream = ({ quality } = {}, streamOptions = {}) => {\n\treturn createBrotliCompress({\n\t\t...streamOptions,\n\t\tparams: {\n\t\t\t[constants.BROTLI_PARAM_QUALITY]:\n\t\t\t\tquality ?? constants.BROTLI_DEFAULT_QUALITY,\n\t\t},\n\t});\n};\nexport const brotliDecompressStream = (options = {}, streamOptions = {}) => {\n\tconst { maxOutputSize, ...params } = options;\n\tconst zlibOptions = Object.keys(params).length\n\t\t? { ...streamOptions, params }\n\t\t: streamOptions;\n\tconst stream = createBrotliDecompress(zlibOptions);\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst originalPush = stream.push.bind(stream);\n\t\tstream.push = (chunk) => {\n\t\t\tif (chunk !== null) {\n\t\t\t\toutputSize += chunk.length;\n\t\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\t\tstream.destroy(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn originalPush(chunk);\n\t\t};\n\t}\n\treturn stream;\n};\n\nexport default {\n\tcompressStream: brotliCompressStream,\n\tdecompressStream: brotliDecompressStream,\n};\n"], | ||
| "mappings": "AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGA,MAAM,uBAAuB,CAAC,EAAE,QAAQ,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC7E,SAAO,qBAAqB;AAAA,IAC3B,GAAG;AAAA,IACH,QAAQ;AAAA,MACP,CAAC,UAAU,oBAAoB,GAC9B,WAAW,UAAU;AAAA,IACvB;AAAA,EACD,CAAC;AACF;AACO,MAAM,yBAAyB,CAAC,UAAU,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC3E,QAAM,EAAE,eAAe,GAAG,OAAO,IAAI;AACrC,QAAM,cAAc,OAAO,KAAK,MAAM,EAAE,SACrC,EAAE,GAAG,eAAe,OAAO,IAC3B;AACH,QAAM,SAAS,uBAAuB,WAAW;AACjD,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,eAAe,OAAO,KAAK,KAAK,MAAM;AAC5C,WAAO,OAAO,CAAC,UAAU;AACxB,UAAI,UAAU,MAAM;AACnB,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,iBAAO;AAAA,YACN,IAAI;AAAA,cACH,+CAA+C,aAAa;AAAA,YAC7D;AAAA,UACD;AACA,iBAAO;AAAA,QACR;AAAA,MACD;AACA,aAAO,aAAa,KAAK;AAAA,IAC1B;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,sBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+23
-3
@@ -17,10 +17,30 @@ import { createTransformStream } from "@datastream/core"; | ||
| }; | ||
| const brotliDecompressStream = (_options = {}, streamOptions = {}) => { | ||
| const brotliDecompressStream = (options = {}, streamOptions = {}) => { | ||
| const { maxOutputSize } = options; | ||
| const engine = new DecompressStream(); | ||
| let outputSize = 0; | ||
| const transform = (chunk, enqueue) => { | ||
| enqueue(engine.decompress(chunk)); | ||
| const result = engine.decompress(chunk); | ||
| if (maxOutputSize != null) { | ||
| outputSize += result.byteLength; | ||
| if (outputSize > maxOutputSize) { | ||
| throw new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ); | ||
| } | ||
| } | ||
| enqueue(result); | ||
| }; | ||
| const flush = (enqueue) => { | ||
| if (engine.result() === BrotliStreamResult.NeedsMoreInput) { | ||
| enqueue(engine.decompress(void 0, 100)); | ||
| const result = engine.decompress(void 0, 100); | ||
| if (maxOutputSize != null) { | ||
| outputSize += result.byteLength; | ||
| if (outputSize > maxOutputSize) { | ||
| throw new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ); | ||
| } | ||
| } | ||
| enqueue(result); | ||
| } | ||
@@ -27,0 +47,0 @@ }; |
| { | ||
| "version": 3, | ||
| "sources": ["brotli.web.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n// CompressionStream\n// - https://caniuse.com/?search=CompressionStream\n// - doesn't support `br` - https://github.com/httptoolkit/brotli-wasm\n// - not supported on firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1586639\n// - not supported in safari\nimport { createTransformStream } from \"@datastream/core\";\nimport brotliPromise from \"brotli-wasm\"; // Import the default export\n\nconst { CompressStream, DecompressStream, BrotliStreamResult } =\n\tawait brotliPromise; // Import is async in browsers due to wasm requirements!\n\n// https://github.com/httptoolkit/brotli-wasm/issues/14\nexport const brotliCompressStream = (options = {}, streamOptions = {}) => {\n\tconst { quality } = options;\n\tconst engine = new CompressStream(quality ?? 11);\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(engine.compress(chunk));\n\t};\n\tconst flush = (enqueue) => {\n\t\tif (engine.result() === BrotliStreamResult.NeedsMoreInput) {\n\t\t\tenqueue(engine.compress(undefined, 100));\n\t\t}\n\t};\n\treturn createTransformStream(transform, flush, streamOptions);\n};\nexport const brotliDecompressStream = (_options = {}, streamOptions = {}) => {\n\tconst engine = new DecompressStream();\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(engine.decompress(chunk));\n\t};\n\tconst flush = (enqueue) => {\n\t\tif (engine.result() === BrotliStreamResult.NeedsMoreInput) {\n\t\t\tenqueue(engine.decompress(undefined, 100));\n\t\t}\n\t};\n\treturn createTransformStream(transform, flush, streamOptions);\n};\n\nexport default {\n\tcompressStream: brotliCompressStream,\n\tdecompressStream: brotliDecompressStream,\n};\n"], | ||
| "mappings": "AAOA,SAAS,6BAA6B;AACtC,OAAO,mBAAmB;AAE1B,MAAM,EAAE,gBAAgB,kBAAkB,mBAAmB,IAC5D,MAAM;AAGA,MAAM,uBAAuB,CAAC,UAAU,CAAC,GAAG,gBAAgB,CAAC,MAAM;AACzE,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,SAAS,IAAI,eAAe,WAAW,EAAE;AAC/C,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,OAAO,SAAS,KAAK,CAAC;AAAA,EAC/B;AACA,QAAM,QAAQ,CAAC,YAAY;AAC1B,QAAI,OAAO,OAAO,MAAM,mBAAmB,gBAAgB;AAC1D,cAAQ,OAAO,SAAS,QAAW,GAAG,CAAC;AAAA,IACxC;AAAA,EACD;AACA,SAAO,sBAAsB,WAAW,OAAO,aAAa;AAC7D;AACO,MAAM,yBAAyB,CAAC,WAAW,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC5E,QAAM,SAAS,IAAI,iBAAiB;AACpC,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,OAAO,WAAW,KAAK,CAAC;AAAA,EACjC;AACA,QAAM,QAAQ,CAAC,YAAY;AAC1B,QAAI,OAAO,OAAO,MAAM,mBAAmB,gBAAgB;AAC1D,cAAQ,OAAO,WAAW,QAAW,GAAG,CAAC;AAAA,IAC1C;AAAA,EACD;AACA,SAAO,sBAAsB,WAAW,OAAO,aAAa;AAC7D;AAEA,IAAO,qBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n// CompressionStream\n// - https://caniuse.com/?search=CompressionStream\n// - doesn't support `br` - https://github.com/httptoolkit/brotli-wasm\n// - not supported on firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1586639\n// - not supported in safari\nimport { createTransformStream } from \"@datastream/core\";\nimport brotliPromise from \"brotli-wasm\"; // Import the default export\n\nconst { CompressStream, DecompressStream, BrotliStreamResult } =\n\tawait brotliPromise; // Import is async in browsers due to wasm requirements!\n\n// https://github.com/httptoolkit/brotli-wasm/issues/14\nexport const brotliCompressStream = (options = {}, streamOptions = {}) => {\n\tconst { quality } = options;\n\tconst engine = new CompressStream(quality ?? 11);\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(engine.compress(chunk));\n\t};\n\tconst flush = (enqueue) => {\n\t\tif (engine.result() === BrotliStreamResult.NeedsMoreInput) {\n\t\t\tenqueue(engine.compress(undefined, 100));\n\t\t}\n\t};\n\treturn createTransformStream(transform, flush, streamOptions);\n};\nexport const brotliDecompressStream = (options = {}, streamOptions = {}) => {\n\tconst { maxOutputSize } = options;\n\tconst engine = new DecompressStream();\n\tlet outputSize = 0;\n\tconst transform = (chunk, enqueue) => {\n\t\tconst result = engine.decompress(chunk);\n\t\tif (maxOutputSize != null) {\n\t\t\toutputSize += result.byteLength;\n\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tenqueue(result);\n\t};\n\tconst flush = (enqueue) => {\n\t\tif (engine.result() === BrotliStreamResult.NeedsMoreInput) {\n\t\t\tconst result = engine.decompress(undefined, 100);\n\t\t\tif (maxOutputSize != null) {\n\t\t\t\toutputSize += result.byteLength;\n\t\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tenqueue(result);\n\t\t}\n\t};\n\treturn createTransformStream(transform, flush, streamOptions);\n};\n\nexport default {\n\tcompressStream: brotliCompressStream,\n\tdecompressStream: brotliDecompressStream,\n};\n"], | ||
| "mappings": "AAOA,SAAS,6BAA6B;AACtC,OAAO,mBAAmB;AAE1B,MAAM,EAAE,gBAAgB,kBAAkB,mBAAmB,IAC5D,MAAM;AAGA,MAAM,uBAAuB,CAAC,UAAU,CAAC,GAAG,gBAAgB,CAAC,MAAM;AACzE,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,SAAS,IAAI,eAAe,WAAW,EAAE;AAC/C,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,OAAO,SAAS,KAAK,CAAC;AAAA,EAC/B;AACA,QAAM,QAAQ,CAAC,YAAY;AAC1B,QAAI,OAAO,OAAO,MAAM,mBAAmB,gBAAgB;AAC1D,cAAQ,OAAO,SAAS,QAAW,GAAG,CAAC;AAAA,IACxC;AAAA,EACD;AACA,SAAO,sBAAsB,WAAW,OAAO,aAAa;AAC7D;AACO,MAAM,yBAAyB,CAAC,UAAU,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC3E,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,SAAS,IAAI,iBAAiB;AACpC,MAAI,aAAa;AACjB,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,UAAM,SAAS,OAAO,WAAW,KAAK;AACtC,QAAI,iBAAiB,MAAM;AAC1B,oBAAc,OAAO;AACrB,UAAI,aAAa,eAAe;AAC/B,cAAM,IAAI;AAAA,UACT,+CAA+C,aAAa;AAAA,QAC7D;AAAA,MACD;AAAA,IACD;AACA,YAAQ,MAAM;AAAA,EACf;AACA,QAAM,QAAQ,CAAC,YAAY;AAC1B,QAAI,OAAO,OAAO,MAAM,mBAAmB,gBAAgB;AAC1D,YAAM,SAAS,OAAO,WAAW,QAAW,GAAG;AAC/C,UAAI,iBAAiB,MAAM;AAC1B,sBAAc,OAAO;AACrB,YAAI,aAAa,eAAe;AAC/B,gBAAM,IAAI;AAAA,YACT,+CAA+C,aAAa;AAAA,UAC7D;AAAA,QACD;AAAA,MACD;AACA,cAAQ,MAAM;AAAA,IACf;AAAA,EACD;AACA,SAAO,sBAAsB,WAAW,OAAO,aAAa;AAC7D;AAEA,IAAO,qBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+22
-2
@@ -6,4 +6,24 @@ import { createDeflate, createInflate } from "node:zlib"; | ||
| }; | ||
| const deflateDecompressStream = (_options = {}, streamOptions = {}) => { | ||
| return createInflate(streamOptions); | ||
| const deflateDecompressStream = (options = {}, streamOptions = {}) => { | ||
| const { maxOutputSize } = options; | ||
| const stream = createInflate(streamOptions); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const originalPush = stream.push.bind(stream); | ||
| stream.push = (chunk) => { | ||
| if (chunk !== null) { | ||
| outputSize += chunk.length; | ||
| if (outputSize > maxOutputSize) { | ||
| stream.destroy( | ||
| new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return false; | ||
| } | ||
| } | ||
| return originalPush(chunk); | ||
| }; | ||
| } | ||
| return stream; | ||
| }; | ||
@@ -10,0 +30,0 @@ var deflate_node_default = { |
| { | ||
| "version": 3, | ||
| "sources": ["deflate.node.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createDeflate, createInflate } from \"node:zlib\";\n\n// TODO benchmark against `fflate`\n// quality -1 - 9\nexport const deflateCompressStream = (options = {}, _streamOptions = {}) => {\n\tconst { quality, ...rest } = options;\n\treturn createDeflate({ ...rest, level: rest.level ?? quality });\n};\nexport const deflateDecompressStream = (_options = {}, streamOptions = {}) => {\n\treturn createInflate(streamOptions);\n};\n\nexport default {\n\tcompressStream: deflateCompressStream,\n\tdecompressStream: deflateDecompressStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,eAAe,qBAAqB;AAItC,MAAM,wBAAwB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC3E,QAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAC7B,SAAO,cAAc,EAAE,GAAG,MAAM,OAAO,KAAK,SAAS,QAAQ,CAAC;AAC/D;AACO,MAAM,0BAA0B,CAAC,WAAW,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC7E,SAAO,cAAc,aAAa;AACnC;AAEA,IAAO,uBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createDeflate, createInflate } from \"node:zlib\";\n\n// quality -1 - 9\nexport const deflateCompressStream = (options = {}, _streamOptions = {}) => {\n\tconst { quality, ...rest } = options;\n\treturn createDeflate({ ...rest, level: rest.level ?? quality });\n};\nexport const deflateDecompressStream = (options = {}, streamOptions = {}) => {\n\tconst { maxOutputSize } = options;\n\tconst stream = createInflate(streamOptions);\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst originalPush = stream.push.bind(stream);\n\t\tstream.push = (chunk) => {\n\t\t\tif (chunk !== null) {\n\t\t\t\toutputSize += chunk.length;\n\t\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\t\tstream.destroy(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn originalPush(chunk);\n\t\t};\n\t}\n\treturn stream;\n};\n\nexport default {\n\tcompressStream: deflateCompressStream,\n\tdecompressStream: deflateDecompressStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,eAAe,qBAAqB;AAGtC,MAAM,wBAAwB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC3E,QAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAC7B,SAAO,cAAc,EAAE,GAAG,MAAM,OAAO,KAAK,SAAS,QAAQ,CAAC;AAC/D;AACO,MAAM,0BAA0B,CAAC,UAAU,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC5E,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,SAAS,cAAc,aAAa;AAC1C,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,eAAe,OAAO,KAAK,KAAK,MAAM;AAC5C,WAAO,OAAO,CAAC,UAAU;AACxB,UAAI,UAAU,MAAM;AACnB,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,iBAAO;AAAA,YACN,IAAI;AAAA,cACH,+CAA+C,aAAa;AAAA,YAC7D;AAAA,UACD;AACA,iBAAO;AAAA,QACR;AAAA,MACD;AACA,aAAO,aAAa,KAAK;AAAA,IAC1B;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,uBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+25
-2
| const deflateCompressStream = (_options = {}, _streamOptions = {}) => { | ||
| return new CompressionStream("deflate"); | ||
| }; | ||
| const deflateDecompressStream = (_options = {}, _streamOptions = {}) => { | ||
| return new DecompressionStream("deflate"); | ||
| const deflateDecompressStream = (options = {}, _streamOptions = {}) => { | ||
| const { maxOutputSize } = options; | ||
| const decompressor = new DecompressionStream("deflate"); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const limiter = new TransformStream({ | ||
| transform(chunk, controller) { | ||
| outputSize += chunk.byteLength; | ||
| if (outputSize > maxOutputSize) { | ||
| controller.error( | ||
| new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return; | ||
| } | ||
| controller.enqueue(chunk); | ||
| } | ||
| }); | ||
| return { | ||
| readable: decompressor.readable.pipeThrough(limiter), | ||
| writable: decompressor.writable | ||
| }; | ||
| } | ||
| return decompressor; | ||
| }; | ||
@@ -7,0 +30,0 @@ var deflate_web_default = { |
| { | ||
| "version": 3, | ||
| "sources": ["deflate.web.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n/* global CompressionStream, DecompressionStream */\n// CompressionStream\n// - https://caniuse.com/?search=CompressionStream\n// - not supported on firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1586639\n// - not supported in safari\n\nexport const deflateCompressStream = (_options = {}, _streamOptions = {}) => {\n\treturn new CompressionStream(\"deflate\");\n};\nexport const deflateDecompressStream = (_options = {}, _streamOptions = {}) => {\n\treturn new DecompressionStream(\"deflate\");\n};\n\nexport default {\n\tcompressStream: deflateCompressStream,\n\tdecompressStream: deflateDecompressStream,\n};\n"], | ||
| "mappings": "AAQO,MAAM,wBAAwB,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC5E,SAAO,IAAI,kBAAkB,SAAS;AACvC;AACO,MAAM,0BAA0B,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC9E,SAAO,IAAI,oBAAoB,SAAS;AACzC;AAEA,IAAO,sBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n/* global CompressionStream, DecompressionStream */\n// CompressionStream\n// - https://caniuse.com/?search=CompressionStream\n// - not supported on firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1586639\n// - not supported in safari\n\nexport const deflateCompressStream = (_options = {}, _streamOptions = {}) => {\n\treturn new CompressionStream(\"deflate\");\n};\nexport const deflateDecompressStream = (options = {}, _streamOptions = {}) => {\n\tconst { maxOutputSize } = options;\n\tconst decompressor = new DecompressionStream(\"deflate\");\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst limiter = new TransformStream({\n\t\t\ttransform(chunk, controller) {\n\t\t\t\toutputSize += chunk.byteLength;\n\t\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\t\tcontroller.error(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t},\n\t\t});\n\t\treturn {\n\t\t\treadable: decompressor.readable.pipeThrough(limiter),\n\t\t\twritable: decompressor.writable,\n\t\t};\n\t}\n\treturn decompressor;\n};\n\nexport default {\n\tcompressStream: deflateCompressStream,\n\tdecompressStream: deflateDecompressStream,\n};\n"], | ||
| "mappings": "AAQO,MAAM,wBAAwB,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC5E,SAAO,IAAI,kBAAkB,SAAS;AACvC;AACO,MAAM,0BAA0B,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC7E,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,eAAe,IAAI,oBAAoB,SAAS;AACtD,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,UAAU,IAAI,gBAAgB;AAAA,MACnC,UAAU,OAAO,YAAY;AAC5B,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,qBAAW;AAAA,YACV,IAAI;AAAA,cACH,+CAA+C,aAAa;AAAA,YAC7D;AAAA,UACD;AACA;AAAA,QACD;AACA,mBAAW,QAAQ,KAAK;AAAA,MACzB;AAAA,IACD,CAAC;AACD,WAAO;AAAA,MACN,UAAU,aAAa,SAAS,YAAY,OAAO;AAAA,MACnD,UAAU,aAAa;AAAA,IACxB;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,sBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+22
-2
@@ -5,4 +5,24 @@ import { createGunzip, createGzip } from "node:zlib"; | ||
| }; | ||
| const gzipDecompressStream = (_options = {}, streamOptions = {}) => { | ||
| return createGunzip(streamOptions); | ||
| const gzipDecompressStream = (options = {}, streamOptions = {}) => { | ||
| const { maxOutputSize } = options; | ||
| const stream = createGunzip(streamOptions); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const originalPush = stream.push.bind(stream); | ||
| stream.push = (chunk) => { | ||
| if (chunk !== null) { | ||
| outputSize += chunk.length; | ||
| if (outputSize > maxOutputSize) { | ||
| stream.destroy( | ||
| new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return false; | ||
| } | ||
| } | ||
| return originalPush(chunk); | ||
| }; | ||
| } | ||
| return stream; | ||
| }; | ||
@@ -9,0 +29,0 @@ var gzip_node_default = { |
| { | ||
| "version": 3, | ||
| "sources": ["gzip.node.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createGunzip, createGzip } from \"node:zlib\";\n\n// quality -1 - 9\nexport const gzipCompressStream = ({ quality } = {}, streamOptions = {}) => {\n\treturn createGzip({ ...streamOptions, level: quality });\n};\nexport const gzipDecompressStream = (_options = {}, streamOptions = {}) => {\n\treturn createGunzip(streamOptions);\n};\n\nexport default {\n\tcompressStream: gzipCompressStream,\n\tdecompressStream: gzipDecompressStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,cAAc,kBAAkB;AAGlC,MAAM,qBAAqB,CAAC,EAAE,QAAQ,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC3E,SAAO,WAAW,EAAE,GAAG,eAAe,OAAO,QAAQ,CAAC;AACvD;AACO,MAAM,uBAAuB,CAAC,WAAW,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC1E,SAAO,aAAa,aAAa;AAClC;AAEA,IAAO,oBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createGunzip, createGzip } from \"node:zlib\";\n\n// quality -1 - 9\nexport const gzipCompressStream = ({ quality } = {}, streamOptions = {}) => {\n\treturn createGzip({ ...streamOptions, level: quality });\n};\nexport const gzipDecompressStream = (options = {}, streamOptions = {}) => {\n\tconst { maxOutputSize } = options;\n\tconst stream = createGunzip(streamOptions);\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst originalPush = stream.push.bind(stream);\n\t\tstream.push = (chunk) => {\n\t\t\tif (chunk !== null) {\n\t\t\t\toutputSize += chunk.length;\n\t\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\t\tstream.destroy(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn originalPush(chunk);\n\t\t};\n\t}\n\treturn stream;\n};\n\nexport default {\n\tcompressStream: gzipCompressStream,\n\tdecompressStream: gzipDecompressStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,cAAc,kBAAkB;AAGlC,MAAM,qBAAqB,CAAC,EAAE,QAAQ,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC3E,SAAO,WAAW,EAAE,GAAG,eAAe,OAAO,QAAQ,CAAC;AACvD;AACO,MAAM,uBAAuB,CAAC,UAAU,CAAC,GAAG,gBAAgB,CAAC,MAAM;AACzE,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,SAAS,aAAa,aAAa;AACzC,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,eAAe,OAAO,KAAK,KAAK,MAAM;AAC5C,WAAO,OAAO,CAAC,UAAU;AACxB,UAAI,UAAU,MAAM;AACnB,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,iBAAO;AAAA,YACN,IAAI;AAAA,cACH,+CAA+C,aAAa;AAAA,YAC7D;AAAA,UACD;AACA,iBAAO;AAAA,QACR;AAAA,MACD;AACA,aAAO,aAAa,KAAK;AAAA,IAC1B;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,oBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+25
-2
| const gzipCompressStream = (_options = {}, _streamOptions = {}) => { | ||
| return new CompressionStream("gzip"); | ||
| }; | ||
| const gzipDecompressStream = (_options = {}, _streamOptions = {}) => { | ||
| return new DecompressionStream("gzip"); | ||
| const gzipDecompressStream = (options = {}, _streamOptions = {}) => { | ||
| const { maxOutputSize } = options; | ||
| const decompressor = new DecompressionStream("gzip"); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const limiter = new TransformStream({ | ||
| transform(chunk, controller) { | ||
| outputSize += chunk.byteLength; | ||
| if (outputSize > maxOutputSize) { | ||
| controller.error( | ||
| new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return; | ||
| } | ||
| controller.enqueue(chunk); | ||
| } | ||
| }); | ||
| return { | ||
| readable: decompressor.readable.pipeThrough(limiter), | ||
| writable: decompressor.writable | ||
| }; | ||
| } | ||
| return decompressor; | ||
| }; | ||
@@ -7,0 +30,0 @@ var gzip_web_default = { |
+2
-2
| { | ||
| "version": 3, | ||
| "sources": ["gzip.web.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n/* global CompressionStream, DecompressionStream */\n// CompressionStream\n// - https://caniuse.com/?search=CompressionStream\n// - not supported on firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1586639\n// - not supported in safari\n\nexport const gzipCompressStream = (_options = {}, _streamOptions = {}) => {\n\treturn new CompressionStream(\"gzip\");\n};\nexport const gzipDecompressStream = (_options = {}, _streamOptions = {}) => {\n\treturn new DecompressionStream(\"gzip\");\n};\n\nexport default {\n\tcompressStream: gzipCompressStream,\n\tdecompressStream: gzipDecompressStream,\n};\n"], | ||
| "mappings": "AAQO,MAAM,qBAAqB,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC,MAAM;AACzE,SAAO,IAAI,kBAAkB,MAAM;AACpC;AACO,MAAM,uBAAuB,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC3E,SAAO,IAAI,oBAAoB,MAAM;AACtC;AAEA,IAAO,mBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n/* global CompressionStream, DecompressionStream */\n// CompressionStream\n// - https://caniuse.com/?search=CompressionStream\n// - not supported on firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1586639\n// - not supported in safari\n\nexport const gzipCompressStream = (_options = {}, _streamOptions = {}) => {\n\treturn new CompressionStream(\"gzip\");\n};\nexport const gzipDecompressStream = (options = {}, _streamOptions = {}) => {\n\tconst { maxOutputSize } = options;\n\tconst decompressor = new DecompressionStream(\"gzip\");\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst limiter = new TransformStream({\n\t\t\ttransform(chunk, controller) {\n\t\t\t\toutputSize += chunk.byteLength;\n\t\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\t\tcontroller.error(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t},\n\t\t});\n\t\treturn {\n\t\t\treadable: decompressor.readable.pipeThrough(limiter),\n\t\t\twritable: decompressor.writable,\n\t\t};\n\t}\n\treturn decompressor;\n};\n\nexport default {\n\tcompressStream: gzipCompressStream,\n\tdecompressStream: gzipDecompressStream,\n};\n"], | ||
| "mappings": "AAQO,MAAM,qBAAqB,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC,MAAM;AACzE,SAAO,IAAI,kBAAkB,MAAM;AACpC;AACO,MAAM,uBAAuB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC1E,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,eAAe,IAAI,oBAAoB,MAAM;AACnD,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,UAAU,IAAI,gBAAgB;AAAA,MACnC,UAAU,OAAO,YAAY;AAC5B,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,qBAAW;AAAA,YACV,IAAI;AAAA,cACH,+CAA+C,aAAa;AAAA,YAC7D;AAAA,UACD;AACA;AAAA,QACD;AACA,mBAAW,QAAQ,KAAK;AAAA,MACzB;AAAA,IACD,CAAC;AACD,WAAO;AAAA,MACN,UAAU,aAAa,SAAS,YAAY,OAAO;AAAA,MACnD,UAAU,aAAa;AAAA,IACxB;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,mBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+5
-5
| { | ||
| "name": "@datastream/compress", | ||
| "version": "0.1.6", | ||
| "version": "0.2.0", | ||
| "description": "Compression and decompression streams for gzip, deflate, brotli, and zstd", | ||
@@ -143,8 +143,8 @@ "type": "module", | ||
| "dependencies": { | ||
| "@datastream/core": "0.1.6" | ||
| "@datastream/core": "0.2.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "brotli-wasm": "3.0.1", | ||
| "protobufjs": "8.0.0", | ||
| "zstd-codec": "0.1.5" | ||
| "brotli-wasm": "^3.0.0", | ||
| "protobufjs": "^8.0.0", | ||
| "zstd-codec": "^0.1.0" | ||
| }, | ||
@@ -151,0 +151,0 @@ "peerDependenciesMeta": { |
+13
-2
@@ -8,5 +8,16 @@ import { createTransformStream } from "@datastream/core"; | ||
| }; | ||
| const protobufDeserializeStream = ({ Type } = {}, streamOptions = {}) => { | ||
| const protobufDeserializeStream = ({ Type, maxOutputSize } = {}, streamOptions = {}) => { | ||
| let outputSize = 0; | ||
| const transform = (chunk, enqueue) => { | ||
| enqueue(Type.decode(chunk)); | ||
| const decoded = Type.decode(chunk); | ||
| if (maxOutputSize != null) { | ||
| const encoded = JSON.stringify(decoded); | ||
| outputSize += encoded?.length ?? 0; | ||
| if (outputSize > maxOutputSize) { | ||
| throw new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ); | ||
| } | ||
| } | ||
| enqueue(decoded); | ||
| }; | ||
@@ -13,0 +24,0 @@ return createTransformStream(transform, streamOptions); |
| { | ||
| "version": 3, | ||
| "sources": ["protobuf.node.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createTransformStream } from \"@datastream/core\";\n\nexport const protobufSerializeStream = ({ Type } = {}, streamOptions = {}) => {\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(Type.encode(Type.create(chunk)).finish());\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport const protobufDeserializeStream = (\n\t{ Type } = {},\n\tstreamOptions = {},\n) => {\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(Type.decode(chunk));\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport default {\n\tserializeStream: protobufSerializeStream,\n\tdeserializeStream: protobufDeserializeStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,6BAA6B;AAE/B,MAAM,0BAA0B,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC7E,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,KAAK,OAAO,KAAK,OAAO,KAAK,CAAC,EAAE,OAAO,CAAC;AAAA,EACjD;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEO,MAAM,4BAA4B,CACxC,EAAE,KAAK,IAAI,CAAC,GACZ,gBAAgB,CAAC,MACb;AACJ,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,KAAK,OAAO,KAAK,CAAC;AAAA,EAC3B;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEA,IAAO,wBAAQ;AAAA,EACd,iBAAiB;AAAA,EACjB,mBAAmB;AACpB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createTransformStream } from \"@datastream/core\";\n\nexport const protobufSerializeStream = ({ Type } = {}, streamOptions = {}) => {\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(Type.encode(Type.create(chunk)).finish());\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport const protobufDeserializeStream = (\n\t{ Type, maxOutputSize } = {},\n\tstreamOptions = {},\n) => {\n\tlet outputSize = 0;\n\tconst transform = (chunk, enqueue) => {\n\t\tconst decoded = Type.decode(chunk);\n\t\tif (maxOutputSize != null) {\n\t\t\tconst encoded = JSON.stringify(decoded);\n\t\t\toutputSize += encoded?.length ?? 0;\n\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tenqueue(decoded);\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport default {\n\tserializeStream: protobufSerializeStream,\n\tdeserializeStream: protobufDeserializeStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,6BAA6B;AAE/B,MAAM,0BAA0B,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC7E,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,KAAK,OAAO,KAAK,OAAO,KAAK,CAAC,EAAE,OAAO,CAAC;AAAA,EACjD;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEO,MAAM,4BAA4B,CACxC,EAAE,MAAM,cAAc,IAAI,CAAC,GAC3B,gBAAgB,CAAC,MACb;AACJ,MAAI,aAAa;AACjB,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,UAAM,UAAU,KAAK,OAAO,KAAK;AACjC,QAAI,iBAAiB,MAAM;AAC1B,YAAM,UAAU,KAAK,UAAU,OAAO;AACtC,oBAAc,SAAS,UAAU;AACjC,UAAI,aAAa,eAAe;AAC/B,cAAM,IAAI;AAAA,UACT,+CAA+C,aAAa;AAAA,QAC7D;AAAA,MACD;AAAA,IACD;AACA,YAAQ,OAAO;AAAA,EAChB;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEA,IAAO,wBAAQ;AAAA,EACd,iBAAiB;AAAA,EACjB,mBAAmB;AACpB;", | ||
| "names": [] | ||
| } |
+13
-2
@@ -8,5 +8,16 @@ import { createTransformStream } from "@datastream/core"; | ||
| }; | ||
| const protobufDeserializeStream = ({ Type } = {}, streamOptions = {}) => { | ||
| const protobufDeserializeStream = ({ Type, maxOutputSize } = {}, streamOptions = {}) => { | ||
| let outputSize = 0; | ||
| const transform = (chunk, enqueue) => { | ||
| enqueue(Type.decode(chunk)); | ||
| const decoded = Type.decode(chunk); | ||
| if (maxOutputSize != null) { | ||
| const encoded = JSON.stringify(decoded); | ||
| outputSize += encoded?.length ?? 0; | ||
| if (outputSize > maxOutputSize) { | ||
| throw new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ); | ||
| } | ||
| } | ||
| enqueue(decoded); | ||
| }; | ||
@@ -13,0 +24,0 @@ return createTransformStream(transform, streamOptions); |
| { | ||
| "version": 3, | ||
| "sources": ["protobuf.web.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createTransformStream } from \"@datastream/core\";\n\nexport const protobufSerializeStream = ({ Type } = {}, streamOptions = {}) => {\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(Type.encode(Type.create(chunk)).finish());\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport const protobufDeserializeStream = (\n\t{ Type } = {},\n\tstreamOptions = {},\n) => {\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(Type.decode(chunk));\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport default {\n\tserializeStream: protobufSerializeStream,\n\tdeserializeStream: protobufDeserializeStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,6BAA6B;AAE/B,MAAM,0BAA0B,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC7E,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,KAAK,OAAO,KAAK,OAAO,KAAK,CAAC,EAAE,OAAO,CAAC;AAAA,EACjD;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEO,MAAM,4BAA4B,CACxC,EAAE,KAAK,IAAI,CAAC,GACZ,gBAAgB,CAAC,MACb;AACJ,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,KAAK,OAAO,KAAK,CAAC;AAAA,EAC3B;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEA,IAAO,uBAAQ;AAAA,EACd,iBAAiB;AAAA,EACjB,mBAAmB;AACpB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createTransformStream } from \"@datastream/core\";\n\nexport const protobufSerializeStream = ({ Type } = {}, streamOptions = {}) => {\n\tconst transform = (chunk, enqueue) => {\n\t\tenqueue(Type.encode(Type.create(chunk)).finish());\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport const protobufDeserializeStream = (\n\t{ Type, maxOutputSize } = {},\n\tstreamOptions = {},\n) => {\n\tlet outputSize = 0;\n\tconst transform = (chunk, enqueue) => {\n\t\tconst decoded = Type.decode(chunk);\n\t\tif (maxOutputSize != null) {\n\t\t\tconst encoded = JSON.stringify(decoded);\n\t\t\toutputSize += encoded?.length ?? 0;\n\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tenqueue(decoded);\n\t};\n\treturn createTransformStream(transform, streamOptions);\n};\n\nexport default {\n\tserializeStream: protobufSerializeStream,\n\tdeserializeStream: protobufDeserializeStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,6BAA6B;AAE/B,MAAM,0BAA0B,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM;AAC7E,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,YAAQ,KAAK,OAAO,KAAK,OAAO,KAAK,CAAC,EAAE,OAAO,CAAC;AAAA,EACjD;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEO,MAAM,4BAA4B,CACxC,EAAE,MAAM,cAAc,IAAI,CAAC,GAC3B,gBAAgB,CAAC,MACb;AACJ,MAAI,aAAa;AACjB,QAAM,YAAY,CAAC,OAAO,YAAY;AACrC,UAAM,UAAU,KAAK,OAAO,KAAK;AACjC,QAAI,iBAAiB,MAAM;AAC1B,YAAM,UAAU,KAAK,UAAU,OAAO;AACtC,oBAAc,SAAS,UAAU;AACjC,UAAI,aAAa,eAAe;AAC/B,cAAM,IAAI;AAAA,UACT,+CAA+C,aAAa;AAAA,QAC7D;AAAA,MACD;AAAA,IACD;AACA,YAAQ,OAAO;AAAA,EAChB;AACA,SAAO,sBAAsB,WAAW,aAAa;AACtD;AAEA,IAAO,uBAAQ;AAAA,EACd,iBAAiB;AAAA,EACjB,mBAAmB;AACpB;", | ||
| "names": [] | ||
| } |
+21
-1
@@ -12,3 +12,23 @@ import { constants, createZstdCompress, createZstdDecompress } from "node:zlib"; | ||
| const zstdDecompressStream = (options = {}, _streamOptions = {}) => { | ||
| return createZstdDecompress(options); | ||
| const { maxOutputSize, ...rest } = options; | ||
| const stream = createZstdDecompress(rest); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const originalPush = stream.push.bind(stream); | ||
| stream.push = (chunk) => { | ||
| if (chunk !== null) { | ||
| outputSize += chunk.length; | ||
| if (outputSize > maxOutputSize) { | ||
| stream.destroy( | ||
| new Error( | ||
| `Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return false; | ||
| } | ||
| } | ||
| return originalPush(chunk); | ||
| }; | ||
| } | ||
| return stream; | ||
| }; | ||
@@ -15,0 +35,0 @@ var zstd_node_default = { |
| { | ||
| "version": 3, | ||
| "sources": ["zstd.node.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { constants, createZstdCompress, createZstdDecompress } from \"node:zlib\";\n\nexport const zstdCompressStream = (options = {}, _streamOptions = {}) => {\n\tconst { quality, ...rest } = options;\n\treturn createZstdCompress({\n\t\t...rest,\n\t\tparams: rest.params ?? {\n\t\t\t[constants.ZSTD_c_compressionLevel]:\n\t\t\t\tquality ?? constants.ZSTD_CLEVEL_DEFAULT,\n\t\t},\n\t});\n};\nexport const zstdDecompressStream = (options = {}, _streamOptions = {}) => {\n\treturn createZstdDecompress(options);\n};\n\nexport default {\n\tcompressStream: zstdCompressStream,\n\tdecompressStream: zstdDecompressStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,WAAW,oBAAoB,4BAA4B;AAE7D,MAAM,qBAAqB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AACxE,QAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAC7B,SAAO,mBAAmB;AAAA,IACzB,GAAG;AAAA,IACH,QAAQ,KAAK,UAAU;AAAA,MACtB,CAAC,UAAU,uBAAuB,GACjC,WAAW,UAAU;AAAA,IACvB;AAAA,EACD,CAAC;AACF;AACO,MAAM,uBAAuB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC1E,SAAO,qBAAqB,OAAO;AACpC;AAEA,IAAO,oBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { constants, createZstdCompress, createZstdDecompress } from \"node:zlib\";\n\nexport const zstdCompressStream = (options = {}, _streamOptions = {}) => {\n\tconst { quality, ...rest } = options;\n\treturn createZstdCompress({\n\t\t...rest,\n\t\tparams: rest.params ?? {\n\t\t\t[constants.ZSTD_c_compressionLevel]:\n\t\t\t\tquality ?? constants.ZSTD_CLEVEL_DEFAULT,\n\t\t},\n\t});\n};\nexport const zstdDecompressStream = (options = {}, _streamOptions = {}) => {\n\tconst { maxOutputSize, ...rest } = options;\n\tconst stream = createZstdDecompress(rest);\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst originalPush = stream.push.bind(stream);\n\t\tstream.push = (chunk) => {\n\t\t\tif (chunk !== null) {\n\t\t\t\toutputSize += chunk.length;\n\t\t\t\tif (outputSize > maxOutputSize) {\n\t\t\t\t\tstream.destroy(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Decompression output exceeds maxOutputSize (${maxOutputSize} bytes)`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn originalPush(chunk);\n\t\t};\n\t}\n\treturn stream;\n};\n\nexport default {\n\tcompressStream: zstdCompressStream,\n\tdecompressStream: zstdDecompressStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,WAAW,oBAAoB,4BAA4B;AAE7D,MAAM,qBAAqB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AACxE,QAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAC7B,SAAO,mBAAmB;AAAA,IACzB,GAAG;AAAA,IACH,QAAQ,KAAK,UAAU;AAAA,MACtB,CAAC,UAAU,uBAAuB,GACjC,WAAW,UAAU;AAAA,IACvB;AAAA,EACD,CAAC;AACF;AACO,MAAM,uBAAuB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC1E,QAAM,EAAE,eAAe,GAAG,KAAK,IAAI;AACnC,QAAM,SAAS,qBAAqB,IAAI;AACxC,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,eAAe,OAAO,KAAK,KAAK,MAAM;AAC5C,WAAO,OAAO,CAAC,UAAU;AACxB,UAAI,UAAU,MAAM;AACnB,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,iBAAO;AAAA,YACN,IAAI;AAAA,cACH,+CAA+C,aAAa;AAAA,YAC7D;AAAA,UACD;AACA,iBAAO;AAAA,QACR;AAAA,MACD;AACA,aAAO,aAAa,KAAK;AAAA,IAC1B;AAAA,EACD;AACA,SAAO;AACR;AAEA,IAAO,oBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
43319
42.94%467
56.71%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated