fix(gzip): Improve gzip streaming decompression, archive analysis and unpacking; add gzip tests

This commit is contained in:
2025-08-18 01:52:20 +00:00
parent 1af585594c
commit 4428638170
5 changed files with 259 additions and 12 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartarchive',
version: '4.2.0',
version: '4.2.1',
description: 'A library for working with archive files, providing utilities for compressing and decompressing data.'
}

View File

@@ -26,8 +26,20 @@ export class CompressGunzipTransform extends plugins.stream.Transform {
// DecompressGunzipTransform class that extends the Node.js Transform stream to
// create a stream that decompresses GZip-compressed data using fflate's gunzip function
export class DecompressGunzipTransform extends plugins.stream.Transform {
private gunzip: any; // fflate.Gunzip instance
constructor() {
super();
// Create a streaming Gunzip decompressor
this.gunzip = new plugins.fflate.Gunzip((chunk, final) => {
// Push decompressed chunks to the output stream
this.push(Buffer.from(chunk));
if (final) {
// Signal end of stream when decompression is complete
this.push(null);
}
});
}
_transform(
@@ -35,17 +47,23 @@ export class DecompressGunzipTransform extends plugins.stream.Transform {
encoding: BufferEncoding,
callback: plugins.stream.TransformCallback,
) {
// Use fflate's gunzip function to decompress the chunk
plugins.fflate.gunzip(chunk, (err, decompressed) => {
if (err) {
// If an error occurs during decompression, pass the error to the callback
callback(err);
} else {
// If decompression is successful, push the decompressed data into the stream
this.push(decompressed);
callback();
}
});
try {
// Feed chunks to the gunzip stream
this.gunzip.push(chunk, false);
callback();
} catch (err) {
callback(err as Error);
}
}
_flush(callback: plugins.stream.TransformCallback) {
try {
// Signal end of input to gunzip
this.gunzip.push(new Uint8Array(0), true);
callback();
} catch (err) {
callback(err as Error);
}
}
}