fix(core): update

This commit is contained in:
2023-11-11 18:28:50 +01:00
parent 3e23534f9d
commit da22f375d2
11 changed files with 484 additions and 60 deletions

View File

@@ -1,36 +1,7 @@
import type { SmartArchive } from './classes.smartarchive.js';
import * as plugins from './plugins.js';
export class DecompressBzip2Transform extends plugins.stream.Transform {
private bzip2Decompressor: plugins.stream.Transform;
constructor() {
super();
// Initialize the bzip2 decompressor once here
this.bzip2Decompressor = plugins.unbzip2Stream();
this.bzip2Decompressor.on('data', (data: Buffer) => {
// When data is decompressed, push it to the stream
this.push(data);
});
this.bzip2Decompressor.on('error', (err) => {
// If an error occurs, emit it on this stream
this.emit('error', err);
});
}
_transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback) {
// Pass the chunk directly to the decompressor
// The decompressor will handle the state across chunks
this.bzip2Decompressor.write(chunk);
callback();
}
_flush(callback: plugins.stream.TransformCallback) {
// When the stream is ending, end the decompressor stream as well
this.bzip2Decompressor.end();
callback();
}
}
import { unbzip2Stream } from './bzip2/index.js';
export class Bzip2Tools {
smartArchiveRef: SmartArchive;
@@ -40,6 +11,6 @@ export class Bzip2Tools {
}
getDecompressionStream() {
return new DecompressBzip2Transform();
return unbzip2Stream();
}
}