fix(core): update

This commit is contained in:
Philipp Kunz 2023-11-06 22:10:20 +01:00
parent 4926f57d83
commit 8efb2b1093
2 changed files with 11 additions and 11 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartstream',
version: '3.0.10',
version: '3.0.11',
description: 'simplifies access to node streams'
}

View File

@ -109,15 +109,15 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
// INSTANCE
private readFunction?: () => Promise<void>;
private writeAndTransformFunction?: IWriteAndTransformFunction<TInput, TOutput>;
private streamEndFunction?: IStreamEndFunction<TOutput>;
private writeFunction?: IWriteAndTransformFunction<TInput, TOutput>;
private finalFunction?: IStreamEndFunction<TOutput>;
private observableSubscription?: plugins.smartrx.rxjs.Subscription;
constructor(optionsArg?: SmartStreamOptions<TInput, TOutput>) {
super(optionsArg);
this.readFunction = optionsArg?.readFunction;
this.writeAndTransformFunction = optionsArg?.writeAndTransformFunction;
this.streamEndFunction = optionsArg?.finalFunction;
this.writeFunction = optionsArg?.writeAndTransformFunction;
this.finalFunction = optionsArg?.finalFunction;
}
public async _read(size: number): Promise<void> {
@ -128,7 +128,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
// Ensure the _write method types the chunk as TInput and encodes TOutput
public async _write(chunk: TInput, encoding: string, callback: (error?: Error | null) => void) {
if (!this.writeAndTransformFunction) {
if (!this.writeFunction) {
return callback(new Error('No stream function provided'));
}
@ -141,7 +141,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
};
try {
const modifiedChunk = await this.writeAndTransformFunction(chunk, tools);
const modifiedChunk = await this.writeFunction(chunk, tools);
if (modifiedChunk) {
if (!this.push(modifiedChunk)) {
// Handle backpressure if necessary
@ -154,24 +154,24 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
}
public async _final(callback: (error?: Error | null) => void) {
if (this.streamEndFunction) {
if (this.finalFunction) {
const tools: IStreamTools = {
truncate: () => callback(),
push: (pipeObject) => this.push(pipeObject),
};
try {
const finalChunk = await this.streamEndFunction(tools);
const finalChunk = await this.finalFunction(tools);
if (finalChunk) {
this.push(finalChunk);
}
callback();
} catch (err) {
callback(err);
}
} else {
callback();
// nothing here
}
this.push(null);
callback();
}
}