UNPKG

igir

Version:

🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.

82 lines (81 loc) • 2.01 kB
import module from "node:module"; import os from "node:os"; import stream from "node:stream"; const require2 = module.createRequire(import.meta.url); class ZstdDecompressStream extends stream.Transform { decompressor = new zstd.Decompressor(); decompressorEnded = false; /** * Decompress the chunk and emit the result. */ _transform(chunk, _encoding, callback) { if (this.decompressorEnded) { callback(new Error("cannot decompress after the compressor has been ended")); return; } this.decompressor.decompressChunk(chunk).then((decompressedChunk) => { if (decompressedChunk.length > 0) { this.push(decompressedChunk); } callback(); }).catch(callback); } /** * @param callback Function to call when flushing is complete */ _flush(callback) { this.finalizeDecompressor(callback); } /** * Clean up native resources. */ _destroy(err, callback) { this.cleanup((cleanupError) => { if (cleanupError) { callback(cleanupError); } else { callback(err); } }); } /** * Clean up method to be called when the stream ends. */ cleanup(callback) { this.finalizeDecompressor(callback); } /** * Finalize the compressor and emit the final output. */ finalizeDecompressor(callback) { if (this.decompressorEnded) { callback(); return; } this.decompressorEnded = true; this.decompressor.end().then((finalData) => { if (finalData.length > 0) { this.push(finalData); } callback(); }).catch(callback); } } const zstd = (() => { try { return require2( `./addon-zstd-1.5.5/prebuilds/${os.platform()}-${os.arch()}/node.node` ); } catch { } return require2("./addon-zstd-1.5.5/build/Release/binding.node"); })(); var zstd_1_5_default = { ...zstd, DecompressStream: ZstdDecompressStream }; export { ZstdDecompressStream, zstd_1_5_default as default }; //# sourceMappingURL=index.js.map