feat(archive): introduce ts_shared browser-compatible layer, refactor Node-specific tools to wrap/shared implementations, and modernize archive handling

This commit is contained in:
2026-01-01 23:09:06 +00:00
parent 4e3c5a8443
commit 6393527c95
37 changed files with 2850 additions and 5105 deletions

View File

@@ -1,5 +1,5 @@
import type { SmartArchive } from './classes.smartarchive.js';
import type { TSupportedMime } from './interfaces.js';
import type { TSupportedMime } from '../ts_shared/interfaces.js';
import * as plugins from './plugins.js';
/**
@@ -8,7 +8,7 @@ import * as plugins from './plugins.js';
export type TDecompressionStream =
| plugins.stream.Transform
| plugins.stream.Duplex
| plugins.tarStream.Extract;
| plugins.smartstream.SmartDuplex<any, any>;
/**
* Result of archive analysis
@@ -53,14 +53,42 @@ export class ArchiveAnalyzer {
*/
private async getDecompressionStream(mimeTypeArg: TSupportedMime): Promise<TDecompressionStream> {
switch (mimeTypeArg) {
case 'application/gzip':
return this.smartArchiveRef.gzipTools.getDecompressionStream();
case 'application/gzip': {
// Use fflate streaming Gunzip - instance must be created once and reused
let gunzip: plugins.fflate.Gunzip;
return new plugins.stream.Transform({
construct(callback) {
gunzip = new plugins.fflate.Gunzip((data, final) => {
this.push(Buffer.from(data));
});
callback();
},
transform(chunk, encoding, callback) {
try {
gunzip.push(chunk, false);
callback();
} catch (err) {
callback(err as Error);
}
},
flush(callback) {
try {
// Signal end of stream with empty final chunk
gunzip.push(new Uint8Array(0), true);
callback();
} catch (err) {
callback(err as Error);
}
}
});
}
case 'application/zip':
return this.smartArchiveRef.zipTools.getDecompressionStream();
case 'application/x-bzip2':
return this.smartArchiveRef.bzip2Tools.getDecompressionStream();
case 'application/x-tar':
return this.smartArchiveRef.tarTools.getDecompressionStream();
// TAR doesn't need decompression, just pass through
return plugins.smartstream.createPassThrough();
default:
// Handle unsupported formats or no decompression needed
return plugins.smartstream.createPassThrough();