fix(core): update

This commit is contained in:
2023-11-13 20:00:28 +01:00
parent 1113020e17
commit 75be95fe45
6 changed files with 30 additions and 16 deletions

View File

@ -38,18 +38,16 @@ export function unbzip2Stream() {
}
var outlength = 0;
const decompressAndPush = async (smartDuplexStream: plugins.smartstream.SmartDuplex) => {
const decompressAndPush = async () => {
if (broken) return;
try {
const resultChunk = decompressBlock();
smartDuplexStream.push(resultChunk);
if (resultChunk) {
//console.error('write at', outlength.toString(16));
outlength += resultChunk.length;
}
return resultChunk;
} catch (e) {
console.error(e);
smartDuplexStream.emit('error', e);
broken = true;
return false;
}
@ -67,13 +65,17 @@ export function unbzip2Stream() {
}
while (!broken && hasBytes - bitReader.bytesRead + 1 >= (25000 + 100000 * blockSize || 4)) {
//console.error('decompressing with', hasBytes - bitReader.bytesRead + 1, 'bytes in buffer');
await decompressAndPush(this);
const result = await decompressAndPush();
console.log('pushing...');
await streamTools.push(result);
}
},
finalFunction: async function (streamTools) {
//console.error(x,'last compressing with', hasBytes, 'bytes in buffer');
while (!broken && bitReader && hasBytes > bitReader.bytesRead) {
await decompressAndPush(this);
const result = await decompressAndPush();
console.log('pushing final...');
streamTools.push(result);
}
if (!broken) {
if (streamCRC !== null) this.emit('error', new Error('input stream ended prematurely'));