fix(core): update

This commit is contained in:
2023-11-13 22:11:24 +01:00
parent 21da75c09a
commit f87359fb97
5 changed files with 22 additions and 16 deletions

View File

@ -49,13 +49,17 @@ export function unbzip2Stream() {
} catch (e) {
console.error(e);
broken = true;
return false;
}
};
let counter = 0;
return new plugins.smartstream.SmartDuplex({
objectMode: true,
// writableObjectMode: true,
name: 'bzip2',
debug: true,
highWaterMark: 1,
writeFunction: async function (data, streamTools) {
//console.error('received', data.length,'bytes in', typeof data);
console.log(`got chunk ${counter++}`)
bufferQueue.push(data);
hasBytes += data.length;
if (bitReader === null) {
@ -66,6 +70,10 @@ export function unbzip2Stream() {
while (!broken && hasBytes - bitReader.bytesRead + 1 >= (25000 + 100000 * blockSize || 4)) {
//console.error('decompressing with', hasBytes - bitReader.bytesRead + 1, 'bytes in buffer');
const result = await decompressAndPush();
if (!result) {
continue;
}
// console.log(result.toString());
await streamTools.push(result);
}
},
@ -73,11 +81,10 @@ export function unbzip2Stream() {
//console.error(x,'last compressing with', hasBytes, 'bytes in buffer');
while (!broken && bitReader && hasBytes > bitReader.bytesRead) {
const result = await decompressAndPush();
streamTools.push(result);
await streamTools.push(result);
}
if (!broken) {
if (streamCRC !== null) this.emit('error', new Error('input stream ended prematurely'));
this.queue(null);
}
},
});