fix(core): update
This commit is contained in:
parent
12c9d8cc9d
commit
7b678cc856
@ -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'
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user