Compare commits

...

2 Commits

Author SHA1 Message Date
788f2665c2 3.0.15 2023-11-11 19:47:21 +01:00
7b678cc856 fix(core): update 2023-11-11 19:47:20 +01:00
3 changed files with 10 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartstream",
"version": "3.0.14",
"version": "3.0.15",
"private": false,
"description": "simplifies access to node streams",
"main": "dist_ts/index.js",

View File

@ -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'
}

View File

@ -1,4 +1,5 @@
import { Transform, type TransformCallback, type TransformOptions } from 'stream';
import { SmartDuplex } from './smartstream.classes.smartduplex.js';
export interface AsyncTransformFunction<TInput, TOutput> {
(chunkArg: TInput): Promise<TOutput>;
@ -7,20 +8,14 @@ export interface AsyncTransformFunction<TInput, TOutput> {
export function createTransformFunction<TInput, TOutput>(
asyncFunction: AsyncTransformFunction<TInput, TOutput>,
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;
}