UNPKG

@ayonli/jsext

Version:

A JavaScript extension package for building strong and modern applications.

91 lines (88 loc) 3.08 kB
'use strict'; var node_zlib = require('node:zlib'); function throwUnsupportedFormatError(format) { throw new TypeError(`Unsupported format: ${format}`); } if (typeof CompressionStream === "undefined") { globalThis.CompressionStream = class CompressionStream { constructor(format) { let impl; if (format === "gzip") { impl = node_zlib.createGzip(); } else if (format === "deflate") { impl = node_zlib.createDeflate(); } else if (format === "deflate-raw") { impl = node_zlib.createDeflateRaw(); } else { throwUnsupportedFormatError(format); } this.readable = new ReadableStream({ start(controller) { impl.on("data", (chunk) => controller.enqueue(chunk)); impl.once("error", (err) => controller.error(err)); impl.once("close", () => controller.close()); }, }); this.writable = new WritableStream({ start(controller) { impl.once("error", (err) => controller.error(err)); impl.once("close", () => controller.error()); }, write(chunk) { impl.write(chunk); }, close() { impl.end(); }, abort(reason) { impl.destroy(reason); }, }); } }; } if (typeof DecompressionStream === "undefined") { globalThis.DecompressionStream = class DecompressionStream { constructor(format) { let impl; if (format === "gzip") { impl = node_zlib.createGunzip(); } else if (format === "deflate") { impl = node_zlib.createInflate(); } else if (format === "deflate-raw") { impl = node_zlib.createInflateRaw(); } else { throwUnsupportedFormatError(format); } this.readable = new ReadableStream({ start(controller) { impl.on("data", (chunk) => controller.enqueue(chunk)); impl.once("error", (err) => controller.error(err)); impl.once("close", () => controller.close()); }, }); this.writable = new WritableStream({ start(controller) { impl.once("error", (err) => controller.error(err)); impl.once("close", () => controller.error()); }, write(chunk) { impl.write(chunk); }, close() { impl.end(); }, abort(reason) { impl.destroy(reason); }, }); } }; } //# sourceMappingURL=index.js.map