fix(WebDuplexStream): Fix errors in WebDuplexStream transformation and test logic

This commit is contained in:
2024-10-13 11:16:46 +02:00
parent f9b8bf33b0
commit 5f2c5f9380
5 changed files with 51 additions and 48 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartstream',
version: '3.0.45',
version: '3.0.46',
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
}

View File

@ -63,6 +63,7 @@ export class WebDuplexStream<TInput = any, TOutput = any> extends TransformStrea
options: WebDuplexStreamOptions<TInput, TOutput>;
constructor(optionsArg: WebDuplexStreamOptions<TInput, TOutput>) {
// here we call into the official web stream api
super({
async transform(chunk, controller) {
// Transformation logic remains unchanged
@ -72,15 +73,14 @@ export class WebDuplexStream<TInput = any, TOutput = any> extends TransformStrea
push: (pushArg: TOutput) => controller.enqueue(pushArg),
};
optionsArg.writeFunction(chunk, tools)
.then(writeReturnChunk => {
// the write return chunk is optional
// just in case the write function returns something other than void.
if (writeReturnChunk) {
controller.enqueue(writeReturnChunk);
}
})
.catch(err => controller.error(err));
try {
const writeReturnChunk = await optionsArg.writeFunction(chunk, tools);
if (writeReturnChunk) { // return chunk is optional
controller.enqueue(writeReturnChunk);
}
} catch (err) {
controller.error(err);
}
} else {
controller.error(new Error('No write function provided'));
}