Compare commits

...

12 Commits

Author SHA1 Message Date
1f67bc0e1e 3.0.13 2023-11-09 15:59:28 +01:00
b15ddd987c fix(core): update 2023-11-09 15:59:28 +01:00
cc43080513 3.0.12 2023-11-07 21:46:47 +01:00
49d235411f fix(core): update 2023-11-07 21:46:46 +01:00
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
5 changed files with 20 additions and 20 deletions

View File

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

0
readme_instructions.md Normal file
View File

View File

@ -10,7 +10,7 @@ tap.test('should handle a read stream', async (tools) => {
const streamWrapper = new smartstream.StreamWrapper([
smartfile.fsStream.createReadStream('./test/assets/readabletext.txt'),
new smartstream.SmartDuplex({
writeAndTransformFunction: async (chunkStringArg: Buffer, streamTools) => {
writeFunction: async (chunkStringArg: Buffer, streamTools) => {
// do something with the stream here
const result = chunkStringArg.toString().substr(0, 100);
streamTools.push('wow =========== \n');
@ -21,7 +21,7 @@ tap.test('should handle a read stream', async (tools) => {
},
}),
new smartstream.SmartDuplex({
writeAndTransformFunction: async (chunkStringArg) => {
writeFunction: async (chunkStringArg) => {
console.log(chunkStringArg.toString());
},
finalFunction: async (tools) => {
@ -37,7 +37,7 @@ tap.test('should create a valid Intake', async (tools) => {
testIntake.pipe(
new smartstream.SmartDuplex({
objectMode: true,
writeAndTransformFunction: async (chunkStringArg: string, streamTools) => {
writeFunction: async (chunkStringArg: string, streamTools) => {
await tools.delayFor(100);
console.log(chunkStringArg);
return chunkStringArg;

View File

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

View File

@ -6,18 +6,18 @@ export interface IStreamTools {
push: (pipeObject: any) => void;
}
export interface IWriteAndTransformFunction<T, rT> {
export interface IStreamWriteFunction<T, rT> {
(chunkArg: T, toolsArg: IStreamTools): Promise<rT>;
}
export interface IStreamEndFunction<rT> {
export interface IStreamFinalFunction<rT> {
(toolsArg: IStreamTools): Promise<rT>;
}
export interface SmartStreamOptions<TInput, TOutput> extends DuplexOptions {
readFunction?: () => Promise<void>;
writeAndTransformFunction?: IWriteAndTransformFunction<TInput, TOutput>;
finalFunction?: IStreamEndFunction<TOutput>;
writeFunction?: IStreamWriteFunction<TInput, TOutput>;
finalFunction?: IStreamFinalFunction<TOutput>;
// Add other custom options if necessary
}
@ -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?: IStreamWriteFunction<TInput, TOutput>;
private finalFunction?: IStreamFinalFunction<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?.writeFunction;
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 {
this.push(null),
// nothing here
}
this.push(null);
callback();
}
}
}