Compare commits

...

10 Commits

Author SHA1 Message Date
d238662bea 3.0.11 2023-11-06 22:10:21 +01:00
8efb2b1093 fix(core): update 2023-11-06 22:10:20 +01:00
4926f57d83 3.0.10 2023-11-06 21:59:26 +01:00
86552f2b1b fix(core): update 2023-11-06 21:59:25 +01:00
353a8ecde6 3.0.9 2023-11-06 21:03:45 +01:00
3e03b81a43 fix(core): update 2023-11-06 21:03:44 +01:00
5e4ec5b837 3.0.8 2023-11-06 20:48:33 +01:00
62796f7151 fix(core): update 2023-11-06 20:48:32 +01:00
2c1d9f05ce 3.0.7 2023-11-04 00:17:04 +01:00
34cbf28972 fix(core): update 2023-11-04 00:17:03 +01:00
4 changed files with 16 additions and 14 deletions

View File

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

View File

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

View File

@ -13,7 +13,9 @@ export class PassThrough extends plugins.stream.Duplex {
if (this.push(chunk, encoding)) { if (this.push(chunk, encoding)) {
callback(); callback();
} else { } else {
this.once('drain', callback); this.once('drain', () => {
callback();
});
} }
} }
} }

View File

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