Compare commits

..

2 Commits

Author SHA1 Message Date
d48ef6eb43 3.0.22 2023-11-13 18:19:11 +01:00
9421c652a2 fix(core): update 2023-11-13 18:19:11 +01:00
3 changed files with 14 additions and 12 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartstream",
"version": "3.0.21",
"version": "3.0.22",
"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.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 {