fix(core): update

This commit is contained in:
Philipp Kunz 2023-11-13 18:19:11 +01:00
parent a6ab15bf1d
commit 9421c652a2
2 changed files with 13 additions and 11 deletions

View File

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

View File

@ -3,7 +3,7 @@ import { Duplex, type DuplexOptions } from 'stream';
export interface IStreamTools {
truncate: () => void;
push: (pipeObject: any) => void;
push: (pipeObject: any) => Promise<void>;
}
export interface IStreamWriteFunction<T, rT> {
@ -80,8 +80,13 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
isTruncated = true;
callback();
},
push: (pushArg: TOutput) => {
this.backpressuredArray.push(pushArg);
push: async (pushArg: TOutput) => {
const canPushMore = this.backpressuredArray.push(pushArg);
if (!canPushMore) {
this.debugLog(`${this.options.name}: cannot push more`);
await this.backpressuredArray.waitForSpace();
this.debugLog(`${this.options.name}: can push more again`);
}
},
};
@ -93,12 +98,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
return;
}
if (modifiedChunk) {
const canPushMore = this.backpressuredArray.push(modifiedChunk);
if (!canPushMore) {
this.debugLog(`${this.options.name}: cannot push more`);
await this.backpressuredArray.waitForSpace();
this.debugLog(`${this.options.name}: can push more again`);
}
await tools.push(modifiedChunk);
}
callback();
writeDeferred.resolve();
@ -115,7 +115,9 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
if (this.options.finalFunction) {
const tools: IStreamTools = {
truncate: () => callback(),
push: (pipeObject) => this.push(pipeObject),
push: async (pipeObject) => {
this.push(pipeObject);
},
};
try {