fix(WebDuplexStream): Fix errors in WebDuplexStream transformation and test logic
This commit is contained in:
@ -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.'
|
||||
}
|
||||
|
@ -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'));
|
||||
}
|
||||
|
Reference in New Issue
Block a user