@datastream/compress
Advanced tools
+14
-5
| // Copyright 2026 will Farrell, and datastream contributors. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { StreamOptions } from "@datastream/core"; | ||
| import type { DatastreamTransform, StreamOptions } from "@datastream/core"; | ||
| export interface BrotliCompressOptions { | ||
| quality?: number; | ||
| maxOutputSize?: number; | ||
| } | ||
| export interface BrotliDecompressOptions { | ||
| maxOutputSize?: number; | ||
| } | ||
| export function brotliCompressStream( | ||
| options?: { quality?: number }, | ||
| options?: BrotliCompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; | ||
| export function brotliDecompressStream( | ||
| options?: Record<string, unknown>, | ||
| options?: BrotliDecompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; |
+4
-0
@@ -25,2 +25,3 @@ import { | ||
| if (outputSize > maxOutputSize) { | ||
| stream.push = originalPush; | ||
| stream.destroy( | ||
@@ -36,2 +37,5 @@ new Error( | ||
| }; | ||
| stream.on("close", () => { | ||
| stream.push = originalPush; | ||
| }); | ||
| } | ||
@@ -38,0 +42,0 @@ return stream; |
| { | ||
| "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 = (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;", | ||
| "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.push = originalPush;\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\tstream.on(\"close\", () => {\n\t\t\tstream.push = originalPush;\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,OAAO;AACd,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;AACA,WAAO,GAAG,SAAS,MAAM;AACxB,aAAO,OAAO;AAAA,IACf,CAAC;AAAA,EACF;AACA,SAAO;AACR;AAEA,IAAO,sBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+15
-5
| // Copyright 2026 will Farrell, and datastream contributors. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { StreamOptions } from "@datastream/core"; | ||
| import type { DatastreamTransform, StreamOptions } from "@datastream/core"; | ||
| export interface DeflateCompressOptions { | ||
| quality?: number; | ||
| level?: number; | ||
| maxOutputSize?: number; | ||
| } | ||
| export interface DeflateDecompressOptions { | ||
| maxOutputSize?: number; | ||
| } | ||
| export function deflateCompressStream( | ||
| options?: Record<string, unknown>, | ||
| options?: DeflateCompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; | ||
| export function deflateDecompressStream( | ||
| options?: Record<string, unknown>, | ||
| options?: DeflateDecompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; |
+29
-2
| import { createDeflate, createInflate } from "node:zlib"; | ||
| const deflateCompressStream = (options = {}, _streamOptions = {}) => { | ||
| const { quality, ...rest } = options; | ||
| return createDeflate({ ...rest, level: rest.level ?? quality }); | ||
| const { quality, maxOutputSize, ...rest } = options; | ||
| const stream = createDeflate({ ...rest, level: rest.level ?? quality }); | ||
| if (maxOutputSize !== null && maxOutputSize !== void 0) { | ||
| let outputSize = 0; | ||
| const originalPush = stream.push.bind(stream); | ||
| stream.push = (chunk) => { | ||
| if (chunk !== null) { | ||
| outputSize += chunk.length; | ||
| if (outputSize > maxOutputSize) { | ||
| stream.push = originalPush; | ||
| stream.destroy( | ||
| new Error( | ||
| `Compression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return false; | ||
| } | ||
| } | ||
| return originalPush(chunk); | ||
| }; | ||
| stream.on("close", () => { | ||
| stream.push = originalPush; | ||
| }); | ||
| } | ||
| return stream; | ||
| }; | ||
@@ -16,2 +39,3 @@ const deflateDecompressStream = (options = {}, streamOptions = {}) => { | ||
| if (outputSize > maxOutputSize) { | ||
| stream.push = originalPush; | ||
| stream.destroy( | ||
@@ -27,2 +51,5 @@ new Error( | ||
| }; | ||
| stream.on("close", () => { | ||
| stream.push = originalPush; | ||
| }); | ||
| } | ||
@@ -29,0 +56,0 @@ return stream; |
| { | ||
| "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// 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;", | ||
| "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, maxOutputSize, ...rest } = options;\n\tconst stream = createDeflate({ ...rest, level: rest.level ?? quality });\n\tif (maxOutputSize !== null && maxOutputSize !== undefined) {\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.push = originalPush;\n\t\t\t\t\tstream.destroy(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Compression 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\tstream.on(\"close\", () => {\n\t\t\tstream.push = originalPush;\n\t\t});\n\t}\n\treturn stream;\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.push = originalPush;\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\tstream.on(\"close\", () => {\n\t\t\tstream.push = originalPush;\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,eAAe,GAAG,KAAK,IAAI;AAC5C,QAAM,SAAS,cAAc,EAAE,GAAG,MAAM,OAAO,KAAK,SAAS,QAAQ,CAAC;AACtE,MAAI,kBAAkB,QAAQ,kBAAkB,QAAW;AAC1D,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,OAAO;AACd,iBAAO;AAAA,YACN,IAAI;AAAA,cACH,6CAA6C,aAAa;AAAA,YAC3D;AAAA,UACD;AACA,iBAAO;AAAA,QACR;AAAA,MACD;AACA,aAAO,aAAa,KAAK;AAAA,IAC1B;AACA,WAAO,GAAG,SAAS,MAAM;AACxB,aAAO,OAAO;AAAA,IACf,CAAC;AAAA,EACF;AACA,SAAO;AACR;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,OAAO;AACd,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;AACA,WAAO,GAAG,SAAS,MAAM;AACxB,aAAO,OAAO;AAAA,IACf,CAAC;AAAA,EACF;AACA,SAAO;AACR;AAEA,IAAO,uBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+26
-2
@@ -1,3 +0,27 @@ | ||
| const deflateCompressStream = (_options = {}, _streamOptions = {}) => { | ||
| return new CompressionStream("deflate"); | ||
| const deflateCompressStream = (options = {}, _streamOptions = {}) => { | ||
| const { maxOutputSize } = options; | ||
| const compressor = new CompressionStream("deflate"); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const transformer = { | ||
| transform(chunk, controller) { | ||
| outputSize += chunk.byteLength; | ||
| if (outputSize > maxOutputSize) { | ||
| controller.error( | ||
| new Error( | ||
| `Compression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return; | ||
| } | ||
| controller.enqueue(chunk); | ||
| } | ||
| }; | ||
| const limiter = new TransformStream(transformer); | ||
| return { | ||
| readable: compressor.readable.pipeThrough(limiter), | ||
| writable: compressor.writable | ||
| }; | ||
| } | ||
| return compressor; | ||
| }; | ||
@@ -4,0 +28,0 @@ const deflateDecompressStream = (options = {}, _streamOptions = {}) => { |
| { | ||
| "version": 3, | ||
| "sources": ["deflate.web.js"], | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n/* global CompressionStream, DecompressionStream, TransformStream */\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 transformer = {\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\tconst limiter = new TransformStream(transformer);\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,cAAc;AAAA,MACnB,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;AACA,UAAM,UAAU,IAAI,gBAAgB,WAAW;AAC/C,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;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n/* global CompressionStream, DecompressionStream, TransformStream */\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\tconst { maxOutputSize } = options;\n\tconst compressor = new CompressionStream(\"deflate\");\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst transformer = {\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`Compression 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\tconst limiter = new TransformStream(transformer);\n\t\treturn {\n\t\t\treadable: compressor.readable.pipeThrough(limiter),\n\t\t\twritable: compressor.writable,\n\t\t};\n\t}\n\treturn compressor;\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 transformer = {\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\tconst limiter = new TransformStream(transformer);\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,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AAC3E,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,aAAa,IAAI,kBAAkB,SAAS;AAClD,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,cAAc;AAAA,MACnB,UAAU,OAAO,YAAY;AAC5B,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,qBAAW;AAAA,YACV,IAAI;AAAA,cACH,6CAA6C,aAAa;AAAA,YAC3D;AAAA,UACD;AACA;AAAA,QACD;AACA,mBAAW,QAAQ,KAAK;AAAA,MACzB;AAAA,IACD;AACA,UAAM,UAAU,IAAI,gBAAgB,WAAW;AAC/C,WAAO;AAAA,MACN,UAAU,WAAW,SAAS,YAAY,OAAO;AAAA,MACjD,UAAU,WAAW;AAAA,IACtB;AAAA,EACD;AACA,SAAO;AACR;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,cAAc;AAAA,MACnB,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;AACA,UAAM,UAAU,IAAI,gBAAgB,WAAW;AAC/C,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": [] | ||
| } |
+14
-5
| // Copyright 2026 will Farrell, and datastream contributors. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { StreamOptions } from "@datastream/core"; | ||
| import type { DatastreamTransform, StreamOptions } from "@datastream/core"; | ||
| export interface GzipCompressOptions { | ||
| quality?: number; | ||
| maxOutputSize?: number; | ||
| } | ||
| export interface GzipDecompressOptions { | ||
| maxOutputSize?: number; | ||
| } | ||
| export function gzipCompressStream( | ||
| options?: Record<string, unknown>, | ||
| options?: GzipCompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; | ||
| export function gzipDecompressStream( | ||
| options?: Record<string, unknown>, | ||
| options?: GzipDecompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; |
+30
-2
| import { createGunzip, createGzip } from "node:zlib"; | ||
| const gzipCompressStream = ({ quality } = {}, streamOptions = {}) => { | ||
| return createGzip({ ...streamOptions, level: quality }); | ||
| const gzipCompressStream = (options = {}, streamOptions = {}) => { | ||
| const { quality, maxOutputSize } = options; | ||
| const stream = createGzip({ ...streamOptions, level: quality }); | ||
| if (maxOutputSize !== null && maxOutputSize !== void 0) { | ||
| let outputSize = 0; | ||
| const originalPush = stream.push.bind(stream); | ||
| stream.push = (chunk) => { | ||
| if (chunk !== null) { | ||
| outputSize += chunk.length; | ||
| if (outputSize > maxOutputSize) { | ||
| stream.push = originalPush; | ||
| stream.destroy( | ||
| new Error( | ||
| `Compression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return false; | ||
| } | ||
| } | ||
| return originalPush(chunk); | ||
| }; | ||
| stream.on("close", () => { | ||
| stream.push = originalPush; | ||
| }); | ||
| } | ||
| return stream; | ||
| }; | ||
@@ -15,2 +39,3 @@ const gzipDecompressStream = (options = {}, streamOptions = {}) => { | ||
| if (outputSize > maxOutputSize) { | ||
| stream.push = originalPush; | ||
| stream.destroy( | ||
@@ -26,2 +51,5 @@ new Error( | ||
| }; | ||
| stream.on("close", () => { | ||
| stream.push = originalPush; | ||
| }); | ||
| } | ||
@@ -28,0 +56,0 @@ return stream; |
| { | ||
| "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\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;", | ||
| "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 = (options = {}, streamOptions = {}) => {\n\tconst { quality, maxOutputSize } = options;\n\tconst stream = createGzip({ ...streamOptions, level: quality });\n\tif (maxOutputSize !== null && maxOutputSize !== undefined) {\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.push = originalPush;\n\t\t\t\t\tstream.destroy(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Compression 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\tstream.on(\"close\", () => {\n\t\t\tstream.push = originalPush;\n\t\t});\n\t}\n\treturn stream;\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.push = originalPush;\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\tstream.on(\"close\", () => {\n\t\t\tstream.push = originalPush;\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,UAAU,CAAC,GAAG,gBAAgB,CAAC,MAAM;AACvE,QAAM,EAAE,SAAS,cAAc,IAAI;AACnC,QAAM,SAAS,WAAW,EAAE,GAAG,eAAe,OAAO,QAAQ,CAAC;AAC9D,MAAI,kBAAkB,QAAQ,kBAAkB,QAAW;AAC1D,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,OAAO;AACd,iBAAO;AAAA,YACN,IAAI;AAAA,cACH,6CAA6C,aAAa;AAAA,YAC3D;AAAA,UACD;AACA,iBAAO;AAAA,QACR;AAAA,MACD;AACA,aAAO,aAAa,KAAK;AAAA,IAC1B;AACA,WAAO,GAAG,SAAS,MAAM;AACxB,aAAO,OAAO;AAAA,IACf,CAAC;AAAA,EACF;AACA,SAAO;AACR;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,OAAO;AACd,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;AACA,WAAO,GAAG,SAAS,MAAM;AACxB,aAAO,OAAO;AAAA,IACf,CAAC;AAAA,EACF;AACA,SAAO;AACR;AAEA,IAAO,oBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
+26
-2
@@ -1,3 +0,27 @@ | ||
| const gzipCompressStream = (_options = {}, _streamOptions = {}) => { | ||
| return new CompressionStream("gzip"); | ||
| const gzipCompressStream = (options = {}, _streamOptions = {}) => { | ||
| const { maxOutputSize } = options; | ||
| const compressor = new CompressionStream("gzip"); | ||
| if (maxOutputSize != null) { | ||
| let outputSize = 0; | ||
| const transformer = { | ||
| transform(chunk, controller) { | ||
| outputSize += chunk.byteLength; | ||
| if (outputSize > maxOutputSize) { | ||
| controller.error( | ||
| new Error( | ||
| `Compression output exceeds maxOutputSize (${maxOutputSize} bytes)` | ||
| ) | ||
| ); | ||
| return; | ||
| } | ||
| controller.enqueue(chunk); | ||
| } | ||
| }; | ||
| const limiter = new TransformStream(transformer); | ||
| return { | ||
| readable: compressor.readable.pipeThrough(limiter), | ||
| writable: compressor.writable | ||
| }; | ||
| } | ||
| return compressor; | ||
| }; | ||
@@ -4,0 +28,0 @@ const gzipDecompressStream = (options = {}, _streamOptions = {}) => { |
+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, TransformStream */\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 transformer = {\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\tconst limiter = new TransformStream(transformer);\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,cAAc;AAAA,MACnB,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;AACA,UAAM,UAAU,IAAI,gBAAgB,WAAW;AAC/C,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;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\n/* global CompressionStream, DecompressionStream, TransformStream */\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\tconst { maxOutputSize } = options;\n\tconst compressor = new CompressionStream(\"gzip\");\n\tif (maxOutputSize != null) {\n\t\tlet outputSize = 0;\n\t\tconst transformer = {\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`Compression 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\tconst limiter = new TransformStream(transformer);\n\t\treturn {\n\t\t\treadable: compressor.readable.pipeThrough(limiter),\n\t\t\twritable: compressor.writable,\n\t\t};\n\t}\n\treturn compressor;\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 transformer = {\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\tconst limiter = new TransformStream(transformer);\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,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM;AACxE,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,aAAa,IAAI,kBAAkB,MAAM;AAC/C,MAAI,iBAAiB,MAAM;AAC1B,QAAI,aAAa;AACjB,UAAM,cAAc;AAAA,MACnB,UAAU,OAAO,YAAY;AAC5B,sBAAc,MAAM;AACpB,YAAI,aAAa,eAAe;AAC/B,qBAAW;AAAA,YACV,IAAI;AAAA,cACH,6CAA6C,aAAa;AAAA,YAC3D;AAAA,UACD;AACA;AAAA,QACD;AACA,mBAAW,QAAQ,KAAK;AAAA,MACzB;AAAA,IACD;AACA,UAAM,UAAU,IAAI,gBAAgB,WAAW;AAC/C,WAAO;AAAA,MACN,UAAU,WAAW,SAAS,YAAY,OAAO;AAAA,MACjD,UAAU,WAAW;AAAA,IACtB;AAAA,EACD;AACA,SAAO;AACR;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,cAAc;AAAA,MACnB,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;AACA,UAAM,UAAU,IAAI,gBAAgB,WAAW;AAC/C,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": [] | ||
| } |
+2
-2
| { | ||
| "name": "@datastream/compress", | ||
| "version": "0.3.0", | ||
| "version": "0.3.1", | ||
| "description": "Compression and decompression streams for gzip, deflate, brotli, and zstd", | ||
@@ -143,3 +143,3 @@ "type": "module", | ||
| "dependencies": { | ||
| "@datastream/core": "0.3.0" | ||
| "@datastream/core": "0.3.1" | ||
| }, | ||
@@ -146,0 +146,0 @@ "peerDependencies": { |
+3
-3
| // Copyright 2026 will Farrell, and datastream contributors. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { StreamOptions } from "@datastream/core"; | ||
| import type { DatastreamTransform, StreamOptions } from "@datastream/core"; | ||
@@ -14,6 +14,6 @@ export interface ProtobufType { | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; | ||
| export function protobufDeserializeStream( | ||
| options?: { Type?: ProtobufType }, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; |
+14
-5
| // Copyright 2026 will Farrell, and datastream contributors. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { StreamOptions } from "@datastream/core"; | ||
| import type { DatastreamTransform, StreamOptions } from "@datastream/core"; | ||
| export interface ZstdCompressOptions { | ||
| quality?: number; | ||
| maxOutputSize?: number; | ||
| } | ||
| export interface ZstdDecompressOptions { | ||
| maxOutputSize?: number; | ||
| } | ||
| export function zstdCompressStream( | ||
| options?: Record<string, unknown>, | ||
| options?: ZstdCompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; | ||
| export function zstdDecompressStream( | ||
| options?: Record<string, unknown>, | ||
| options?: ZstdDecompressOptions, | ||
| streamOptions?: StreamOptions, | ||
| ): unknown; | ||
| ): DatastreamTransform; |
+4
-0
@@ -21,2 +21,3 @@ import { constants, createZstdCompress, createZstdDecompress } from "node:zlib"; | ||
| if (outputSize > maxOutputSize) { | ||
| stream.push = originalPush; | ||
| stream.destroy( | ||
@@ -32,2 +33,5 @@ new Error( | ||
| }; | ||
| stream.on("close", () => { | ||
| stream.push = originalPush; | ||
| }); | ||
| } | ||
@@ -34,0 +38,0 @@ return stream; |
| { | ||
| "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\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;", | ||
| "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.push = originalPush;\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\tstream.on(\"close\", () => {\n\t\t\tstream.push = originalPush;\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,OAAO;AACd,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;AACA,WAAO,GAAG,SAAS,MAAM;AACxB,aAAO,OAAO;AAAA,IACf,CAAC;AAAA,EACF;AACA,SAAO;AACR;AAEA,IAAO,oBAAQ;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACnB;", | ||
| "names": [] | ||
| } |
52793
21.27%609
29.85%+ Added
- Removed
Updated