From 7b678cc856912e4dce79d4e95130f75160a8d1c8 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sat, 11 Nov 2023 19:47:20 +0100 Subject: [PATCH] fix(core): update --- ts/00_commitinfo_data.ts | 2 +- ts/smartstream.functions.ts | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 1619b33..7f92f82 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartstream', - version: '3.0.14', + version: '3.0.15', description: 'simplifies access to node streams' } diff --git a/ts/smartstream.functions.ts b/ts/smartstream.functions.ts index 7f58808..d7ff9ac 100644 --- a/ts/smartstream.functions.ts +++ b/ts/smartstream.functions.ts @@ -1,4 +1,5 @@ import { Transform, type TransformCallback, type TransformOptions } from 'stream'; +import { SmartDuplex } from './smartstream.classes.smartduplex.js'; export interface AsyncTransformFunction { (chunkArg: TInput): Promise; @@ -7,20 +8,14 @@ export interface AsyncTransformFunction { export function createTransformFunction( asyncFunction: AsyncTransformFunction, options?: TransformOptions -): Transform { - const transformStream = new Transform({ +): SmartDuplex { + const smartDuplexStream = new SmartDuplex({ ...options, - objectMode: true, // Ensure we operate in object mode - async transform(chunk: TInput, encoding: string, callback: TransformCallback) { - try { - const transformed = await asyncFunction(chunk); - this.push(transformed); - callback(); - } catch (error) { - callback(error instanceof Error ? error : new Error(String(error))); - } + writeFunction: async (chunkArg, toolsArg) => { + const result = await asyncFunction(chunkArg); + return result; } - }); + }) - return transformStream; + return smartDuplexStream; } \ No newline at end of file