@push.rocks/smartstream 3.0.37 → 3.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/smartstream.plugins.d.ts +1 -1
- package/dist_ts/smartstream.plugins.js +2 -2
- package/dist_ts_web/00_commitinfo_data.d.ts +8 -0
- package/dist_ts_web/00_commitinfo_data.js +9 -0
- package/dist_ts_web/classes.webduplexstream.d.ts +37 -0
- package/dist_ts_web/classes.webduplexstream.js +102 -0
- package/dist_ts_web/convert.d.ts +18 -0
- package/dist_ts_web/convert.js +45 -0
- package/dist_ts_web/index.d.ts +3 -0
- package/dist_ts_web/index.js +4 -0
- package/dist_ts_web/plugins.d.ts +2 -0
- package/dist_ts_web/plugins.js +11 -0
- package/package.json +16 -15
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/smartstream.plugins.ts +1 -1
- package/ts_web/00_commitinfo_data.ts +8 -0
- package/ts_web/classes.webduplexstream.ts +156 -0
- package/ts_web/convert.ts +64 -0
- package/ts_web/index.ts +5 -0
- package/ts_web/plugins.ts +15 -0
- package/assets/denoentry.ts +0 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartstream',
|
|
6
|
-
version: '3.0.
|
|
6
|
+
version: '3.0.39',
|
|
7
7
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx5QkFBeUI7SUFDL0IsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLHNMQUFzTDtDQUNwTSxDQUFBIn0=
|
|
@@ -4,5 +4,5 @@ export { stream };
|
|
|
4
4
|
import * as lik from '@push.rocks/lik';
|
|
5
5
|
import * as smartpromise from '@push.rocks/smartpromise';
|
|
6
6
|
import * as smartrx from '@push.rocks/smartrx';
|
|
7
|
-
import * as webstream from '
|
|
7
|
+
import * as webstream from '../dist_ts_web/index.js';
|
|
8
8
|
export { lik, smartpromise, smartrx, webstream };
|
|
@@ -5,6 +5,6 @@ export { stream };
|
|
|
5
5
|
import * as lik from '@push.rocks/lik';
|
|
6
6
|
import * as smartpromise from '@push.rocks/smartpromise';
|
|
7
7
|
import * as smartrx from '@push.rocks/smartrx';
|
|
8
|
-
import * as webstream from '
|
|
8
|
+
import * as webstream from '../dist_ts_web/index.js';
|
|
9
9
|
export { lik, smartpromise, smartrx, webstream };
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3RyZWFtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYztBQUNkLE9BQU8sS0FBSyxNQUFNLE1BQU0sUUFBUSxDQUFDO0FBRWpDLE9BQU8sRUFBRSxNQUFNLEVBQUUsQ0FBQztBQUVsQixrQkFBa0I7QUFDbEIsT0FBTyxLQUFLLEdBQUcsTUFBTSxpQkFBaUIsQ0FBQztBQUN2QyxPQUFPLEtBQUssWUFBWSxNQUFNLDBCQUEwQixDQUFDO0FBQ3pELE9BQU8sS0FBSyxPQUFPLE1BQU0scUJBQXFCLENBQUM7QUFDL0MsT0FBTyxLQUFLLFNBQVMsTUFBTSx5QkFBeUIsQ0FBQztBQUVyRCxPQUFPLEVBQUUsR0FBRyxFQUFFLFlBQVksRUFBRSxPQUFPLEVBQUUsU0FBUyxFQUFFLENBQUMifQ==
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* autocreated commitinfo by @pushrocks/commitinfo
|
|
3
|
+
*/
|
|
4
|
+
export const commitinfo = {
|
|
5
|
+
name: '@push.rocks/smartstream',
|
|
6
|
+
version: '3.0.39',
|
|
7
|
+
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHNfd2ViLzAwX2NvbW1pdGluZm9fZGF0YS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLFVBQVUsR0FBRztJQUN4QixJQUFJLEVBQUUseUJBQXlCO0lBQy9CLE9BQU8sRUFBRSxRQUFRO0lBQ2pCLFdBQVcsRUFBRSxzTEFBc0w7Q0FDcE0sQ0FBQSJ9
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface IStreamToolsRead<TInput, TOutput> {
|
|
2
|
+
done: () => void;
|
|
3
|
+
write: (writeArg: TInput) => void;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* the read function is called anytime
|
|
7
|
+
* -> the WebDuplexStream is being read from
|
|
8
|
+
* and at the same time if nothing is enqueued
|
|
9
|
+
*/
|
|
10
|
+
export interface IStreamReadFunction<TInput, TOutput> {
|
|
11
|
+
(toolsArg: IStreamToolsRead<TInput, TOutput>): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface IStreamToolsWrite<TInput, TOutput> {
|
|
14
|
+
truncate: () => void;
|
|
15
|
+
push: (pushArg: TOutput) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* the write function can return something.
|
|
19
|
+
* It is called anytime a chunk is written to the stream.
|
|
20
|
+
*/
|
|
21
|
+
export interface IStreamWriteFunction<TInput, TOutput> {
|
|
22
|
+
(chunkArg: TInput, toolsArg: IStreamToolsWrite<TInput, TOutput>): Promise<any>;
|
|
23
|
+
}
|
|
24
|
+
export interface IStreamFinalFunction<TInput, TOutput> {
|
|
25
|
+
(toolsArg: IStreamToolsWrite<TInput, TOutput>): Promise<TOutput>;
|
|
26
|
+
}
|
|
27
|
+
export interface WebDuplexStreamOptions<TInput, TOutput> {
|
|
28
|
+
readFunction?: IStreamReadFunction<TInput, TOutput>;
|
|
29
|
+
writeFunction?: IStreamWriteFunction<TInput, TOutput>;
|
|
30
|
+
finalFunction?: IStreamFinalFunction<TInput, TOutput>;
|
|
31
|
+
}
|
|
32
|
+
export declare class WebDuplexStream<TInput = any, TOutput = any> extends TransformStream<TInput, TOutput> {
|
|
33
|
+
static fromUInt8Array(uint8Array: Uint8Array): WebDuplexStream<Uint8Array, Uint8Array>;
|
|
34
|
+
options: WebDuplexStreamOptions<TInput, TOutput>;
|
|
35
|
+
constructor(optionsArg: WebDuplexStreamOptions<TInput, TOutput>);
|
|
36
|
+
getCustomReadableStream(): ReadableStream<any>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
export class WebDuplexStream extends TransformStream {
|
|
3
|
+
static fromUInt8Array(uint8Array) {
|
|
4
|
+
const stream = new WebDuplexStream({
|
|
5
|
+
writeFunction: async (chunk, { push }) => {
|
|
6
|
+
push(chunk); // Directly push the chunk as is
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
const writer = stream.writable.getWriter();
|
|
11
|
+
writer.write(uint8Array).then(() => writer.close());
|
|
12
|
+
return stream;
|
|
13
|
+
}
|
|
14
|
+
constructor(optionsArg) {
|
|
15
|
+
super({
|
|
16
|
+
async transform(chunk, controller) {
|
|
17
|
+
// Transformation logic remains unchanged
|
|
18
|
+
if (optionsArg?.writeFunction) {
|
|
19
|
+
const tools = {
|
|
20
|
+
truncate: () => controller.terminate(),
|
|
21
|
+
push: (pushArg) => controller.enqueue(pushArg),
|
|
22
|
+
};
|
|
23
|
+
optionsArg.writeFunction(chunk, tools)
|
|
24
|
+
.then(writeReturnChunk => {
|
|
25
|
+
// the write return chunk is optional
|
|
26
|
+
// just in case the write function returns something other than void.
|
|
27
|
+
if (writeReturnChunk) {
|
|
28
|
+
controller.enqueue(writeReturnChunk);
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
.catch(err => controller.error(err));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
controller.error(new Error('No write function provided'));
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
async flush(controller) {
|
|
38
|
+
// Flush logic remains unchanged
|
|
39
|
+
if (optionsArg?.finalFunction) {
|
|
40
|
+
const tools = {
|
|
41
|
+
truncate: () => controller.terminate(),
|
|
42
|
+
push: (pipeObject) => controller.enqueue(pipeObject),
|
|
43
|
+
};
|
|
44
|
+
optionsArg.finalFunction(tools)
|
|
45
|
+
.then(finalChunk => {
|
|
46
|
+
if (finalChunk) {
|
|
47
|
+
controller.enqueue(finalChunk);
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.catch(err => controller.error(err))
|
|
51
|
+
.finally(() => controller.terminate());
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
controller.terminate();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
this.options = optionsArg;
|
|
59
|
+
}
|
|
60
|
+
// Method to create a custom readable stream that integrates the readFunction
|
|
61
|
+
// readFunction is executed whenever the stream is being read from and nothing is enqueued
|
|
62
|
+
getCustomReadableStream() {
|
|
63
|
+
const readableStream = this.readable;
|
|
64
|
+
const options = this.options;
|
|
65
|
+
const customReadable = new ReadableStream({
|
|
66
|
+
async pull(controller) {
|
|
67
|
+
const reader = readableStream.getReader();
|
|
68
|
+
// Check the current state of the original stream
|
|
69
|
+
const { value, done } = await reader.read();
|
|
70
|
+
reader.releaseLock();
|
|
71
|
+
if (done) {
|
|
72
|
+
// If the original stream is done, close the custom readable stream
|
|
73
|
+
controller.close();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
if (value) {
|
|
77
|
+
// If there is data in the original stream, enqueue it and do not execute the readFunction
|
|
78
|
+
controller.enqueue(value);
|
|
79
|
+
}
|
|
80
|
+
else if (options.readFunction) {
|
|
81
|
+
// If the original stream is empty, execute the readFunction and read again
|
|
82
|
+
await options.readFunction({
|
|
83
|
+
done: () => controller.close(),
|
|
84
|
+
write: (writeArg) => controller.enqueue(writeArg),
|
|
85
|
+
});
|
|
86
|
+
const newReader = readableStream.getReader();
|
|
87
|
+
const { value: newValue, done: newDone } = await newReader.read();
|
|
88
|
+
newReader.releaseLock();
|
|
89
|
+
if (newDone) {
|
|
90
|
+
controller.close();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
controller.enqueue(newValue);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return customReadable;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy53ZWJkdXBsZXhzdHJlYW0uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c193ZWIvY2xhc3Nlcy53ZWJkdXBsZXhzdHJlYW0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSxjQUFj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7eUJBQU0sSUFBSSxPQUFPLENBQUMsWUFBWSxFQUFFLENBQUM7d0JBQ2hDLDJFQUEyRTt3QkFDM0UsTUFBTSxPQUFPLENBQUMsWUFBWSxDQUFDOzRCQUN6QixJQUFJLEVBQUUsR0FBRyxFQUFFLENBQUMsVUFBVSxDQUFDLEtBQUssRUFBRTs0QkFDOUIsS0FBSyxFQUFFLENBQUMsUUFBUSxFQUFFLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLFFBQVEsQ0FBQzt5QkFDbEQsQ0FBQyxDQUFDO3dCQUVILE1BQU0sU0FBUyxHQUFHLGNBQWMsQ0FBQyxTQUFTLEVBQUUsQ0FBQzt3QkFDN0MsTUFBTSxFQUFFLEtBQUssRUFBRSxRQUFRLEVBQUUsSUFBSSxFQUFFLE9BQU8sRUFBRSxHQUFHLE1BQU0sU0FBUyxDQUFDLElBQUksRUFBRSxDQUFDO3dCQUNsRSxTQUFTLENBQUMsV0FBVyxFQUFFLENBQUM7d0JBRXhCLElBQUksT0FBTyxFQUFFLENBQUM7NEJBQ1osVUFBVSxDQUFDLEtBQUssRUFBRSxDQUFDO3dCQUNyQixDQUFDOzZCQUFNLENBQUM7NEJBQ04sVUFBVSxDQUFDLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQzt3QkFDL0IsQ0FBQztvQkFDSCxDQUFDO2dCQUNILENBQUM7WUFDSCxDQUFDO1NBQ0YsQ0FBQyxDQUFDO1FBRUgsT0FBTyxjQUFjLENBQUM7SUFDeEIsQ0FBQztDQUNGIn0=
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IDuplexStream {
|
|
2
|
+
read(): any;
|
|
3
|
+
write(chunk: any, callback?: (error?: Error | null) => void): boolean;
|
|
4
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
5
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
6
|
+
end(callback?: () => void): void;
|
|
7
|
+
destroy(error?: Error): void;
|
|
8
|
+
}
|
|
9
|
+
export interface IReadableStreamOptions {
|
|
10
|
+
highWaterMark?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface IWritableStreamOptions {
|
|
13
|
+
highWaterMark?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function convertDuplexToWebStream(duplex: IDuplexStream): {
|
|
16
|
+
readable: ReadableStream;
|
|
17
|
+
writable: WritableStream;
|
|
18
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function convertDuplexToWebStream(duplex) {
|
|
2
|
+
const readable = new ReadableStream({
|
|
3
|
+
start(controller) {
|
|
4
|
+
duplex.on('readable', () => {
|
|
5
|
+
let chunk;
|
|
6
|
+
while (null !== (chunk = duplex.read())) {
|
|
7
|
+
controller.enqueue(chunk);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
duplex.on('end', () => {
|
|
11
|
+
controller.close();
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
cancel(reason) {
|
|
15
|
+
duplex.destroy(new Error(reason));
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const writable = new WritableStream({
|
|
19
|
+
write(chunk) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const isBackpressured = !duplex.write(chunk, (error) => {
|
|
22
|
+
if (error) {
|
|
23
|
+
reject(error);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
resolve();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (isBackpressured) {
|
|
30
|
+
duplex.once('drain', resolve);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
close() {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
duplex.end(resolve);
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
abort(reason) {
|
|
40
|
+
duplex.destroy(new Error(reason));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return { readable, writable };
|
|
44
|
+
}
|
|
45
|
+
//#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UFBTSxDQUFDLEtBQUssQ0FBQyxLQUFLLEVBQUUsQ0FBQyxLQUFLLEVBQUUsRUFBRTtvQkFDckQsSUFBSSxLQUFLLEVBQUUsQ0FBQzt3QkFDVixNQUFNLENBQUMsS0FBSyxDQUFDLENBQUM7b0JBQ2hCLENBQUM7eUJBQU0sQ0FBQzt3QkFDTixPQUFPLEVBQUUsQ0FBQztvQkFDWixDQUFDO2dCQUNILENBQUMsQ0FBQyxDQUFDO2dCQUVILElBQUksZUFBZSxFQUFFLENBQUM7b0JBQ3BCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFDO2dCQUNoQyxDQUFDO1lBQ0gsQ0FBQyxDQUFDLENBQUM7UUFDTCxDQUFDO1FBQ0QsS0FBSztZQUNILE9BQU8sSUFBSSxPQUFPLENBQU8sQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQUU7Z0JBQzNDLE1BQU0sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7WUFDdEIsQ0FBQyxDQUFDLENBQUM7UUFDTCxDQUFDO1FBQ0QsS0FBSyxDQUFDLE1BQU07WUFDVixNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksS0FBSyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7UUFDcEMsQ0FBQztLQUNGLENBQUMsQ0FBQztJQUVILE9BQU8sRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLENBQUM7QUFDaEMsQ0FBQyJ9
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import './plugins.js';
|
|
2
|
+
export * from './classes.webduplexstream.js';
|
|
3
|
+
export { convertDuplexToWebStream, } from './convert.js';
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c193ZWIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxjQUFjLENBQUM7QUFDdEIsY0FBYyw4QkFBOEIsQ0FBQztBQUM3QyxPQUFPLEVBQ0wsd0JBQXdCLEdBQ3pCLE1BQU0sY0FBYyxDQUFDIn0=
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @push.rocks scope
|
|
2
|
+
import * as smartenv from '@push.rocks/smartenv';
|
|
3
|
+
export { smartenv, };
|
|
4
|
+
// lets setup dependencies
|
|
5
|
+
const smartenvInstance = new smartenv.Smartenv();
|
|
6
|
+
await smartenvInstance.getSafeNodeModule('stream/web', async (moduleArg) => {
|
|
7
|
+
globalThis.ReadableStream = moduleArg.ReadableStream;
|
|
8
|
+
globalThis.WritableStream = moduleArg.WritableStream;
|
|
9
|
+
globalThis.TransformStream = moduleArg.TransformStream;
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzX3dlYi9wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG9CQUFvQjtBQUNwQixPQUFPLEtBQUssUUFBUSxNQUFNLHNCQUFzQixDQUFDO0FBRWpELE9BQU8sRUFDTCxRQUFRLEdBQ1QsQ0FBQTtBQUVELDBCQUEwQjtBQUMxQixNQUFNLGdCQUFnQixHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsRUFBRSxDQUFDO0FBRWpELE1BQU0sZ0JBQWdCLENBQUMsaUJBQWlCLENBQThCLFlBQVksRUFBRSxLQUFLLEVBQUUsU0FBUyxFQUFFLEVBQUU7SUFDdEcsVUFBVSxDQUFDLGNBQWMsR0FBRyxTQUFTLENBQUMsY0FBYyxDQUFDO0lBQ3JELFVBQVUsQ0FBQyxjQUFjLEdBQUcsU0FBUyxDQUFDLGNBQWMsQ0FBQztJQUNyRCxVQUFVLENBQUMsZUFBZSxHQUFHLFNBQVMsQ0FBQyxlQUFlLENBQUM7QUFDekQsQ0FBQyxDQUFDLENBQUEifQ==
|
package/package.json
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartstream",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.39",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.",
|
|
6
|
-
"main": "dist_ts/index.js",
|
|
7
|
-
"typings": "dist_ts/index.d.ts",
|
|
8
6
|
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist_ts/index.js",
|
|
9
|
+
"./web": "./dist_ts_web/index.js"
|
|
10
|
+
},
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
|
-
"url": "
|
|
13
|
+
"url": "https://code.foss.global/push.rocks/smartstream.git"
|
|
12
14
|
},
|
|
13
15
|
"author": "Lossless GmbH",
|
|
14
16
|
"license": "MIT",
|
|
15
17
|
"bugs": {
|
|
16
18
|
"url": "https://gitlab.com/push.rocks/smartstream/issues"
|
|
17
19
|
},
|
|
18
|
-
"homepage": "https://
|
|
20
|
+
"homepage": "https://code.foss.global/push.rocks/smartstream",
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"@git.zone/tsbuild": "^2.1.
|
|
22
|
+
"@git.zone/tsbuild": "^2.1.80",
|
|
21
23
|
"@git.zone/tsrun": "^1.2.44",
|
|
22
|
-
"@git.zone/tstest": "^1.0.
|
|
23
|
-
"@push.rocks/smartfile": "^11.0.
|
|
24
|
-
"@push.rocks/tapbundle": "^5.0.
|
|
25
|
-
"@types/node": "^20.
|
|
24
|
+
"@git.zone/tstest": "^1.0.90",
|
|
25
|
+
"@push.rocks/smartfile": "^11.0.15",
|
|
26
|
+
"@push.rocks/tapbundle": "^5.0.23",
|
|
27
|
+
"@types/node": "^20.12.12"
|
|
26
28
|
},
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"@push.rocks/lik": "^6.0.
|
|
30
|
+
"@push.rocks/lik": "^6.0.15",
|
|
31
|
+
"@push.rocks/smartenv": "^5.0.12",
|
|
29
32
|
"@push.rocks/smartpromise": "^4.0.3",
|
|
30
|
-
"@push.rocks/smartrx": "^3.0.7"
|
|
31
|
-
"@push.rocks/webstream": "^1.0.8"
|
|
33
|
+
"@push.rocks/smartrx": "^3.0.7"
|
|
32
34
|
},
|
|
33
35
|
"browserslist": [
|
|
34
36
|
"last 1 chrome versions"
|
|
@@ -66,7 +68,6 @@
|
|
|
66
68
|
],
|
|
67
69
|
"scripts": {
|
|
68
70
|
"test": "(tstest test/)",
|
|
69
|
-
"build": "(tsbuild)"
|
|
70
|
-
"buildDocs": "tsdoc"
|
|
71
|
+
"build": "(tsbuild tsfolders --web --allowimplicitany)"
|
|
71
72
|
}
|
|
72
73
|
}
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartstream',
|
|
6
|
-
version: '3.0.
|
|
6
|
+
version: '3.0.39',
|
|
7
7
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
8
|
}
|
|
@@ -7,7 +7,7 @@ export { stream };
|
|
|
7
7
|
import * as lik from '@push.rocks/lik';
|
|
8
8
|
import * as smartpromise from '@push.rocks/smartpromise';
|
|
9
9
|
import * as smartrx from '@push.rocks/smartrx';
|
|
10
|
-
import * as webstream from '
|
|
10
|
+
import * as webstream from '../dist_ts_web/index.js';
|
|
11
11
|
|
|
12
12
|
export { lik, smartpromise, smartrx, webstream };
|
|
13
13
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* autocreated commitinfo by @pushrocks/commitinfo
|
|
3
|
+
*/
|
|
4
|
+
export const commitinfo = {
|
|
5
|
+
name: '@push.rocks/smartstream',
|
|
6
|
+
version: '3.0.39',
|
|
7
|
+
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// ========================================
|
|
5
|
+
// READ
|
|
6
|
+
// ========================================
|
|
7
|
+
export interface IStreamToolsRead<TInput, TOutput> {
|
|
8
|
+
done: () => void;
|
|
9
|
+
write: (writeArg: TInput) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* the read function is called anytime
|
|
14
|
+
* -> the WebDuplexStream is being read from
|
|
15
|
+
* and at the same time if nothing is enqueued
|
|
16
|
+
*/
|
|
17
|
+
export interface IStreamReadFunction<TInput, TOutput> {
|
|
18
|
+
(toolsArg: IStreamToolsRead<TInput, TOutput>): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ========================================
|
|
22
|
+
// WRITE
|
|
23
|
+
// ========================================
|
|
24
|
+
export interface IStreamToolsWrite<TInput, TOutput> {
|
|
25
|
+
truncate: () => void;
|
|
26
|
+
push: (pushArg: TOutput) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* the write function can return something.
|
|
31
|
+
* It is called anytime a chunk is written to the stream.
|
|
32
|
+
*/
|
|
33
|
+
export interface IStreamWriteFunction<TInput, TOutput> {
|
|
34
|
+
(chunkArg: TInput, toolsArg: IStreamToolsWrite<TInput, TOutput>): Promise<any>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IStreamFinalFunction<TInput, TOutput> {
|
|
38
|
+
(toolsArg: IStreamToolsWrite<TInput, TOutput>): Promise<TOutput>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface WebDuplexStreamOptions<TInput, TOutput> {
|
|
42
|
+
readFunction?: IStreamReadFunction<TInput, TOutput>;
|
|
43
|
+
writeFunction?: IStreamWriteFunction<TInput, TOutput>;
|
|
44
|
+
finalFunction?: IStreamFinalFunction<TInput, TOutput>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class WebDuplexStream<TInput = any, TOutput = any> extends TransformStream<TInput, TOutput> {
|
|
48
|
+
static fromUInt8Array(uint8Array: Uint8Array): WebDuplexStream<Uint8Array, Uint8Array> {
|
|
49
|
+
const stream = new WebDuplexStream<Uint8Array, Uint8Array>({
|
|
50
|
+
writeFunction: async (chunk, { push }) => {
|
|
51
|
+
push(chunk); // Directly push the chunk as is
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const writer = stream.writable.getWriter();
|
|
57
|
+
writer.write(uint8Array).then(() => writer.close());
|
|
58
|
+
|
|
59
|
+
return stream;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// INSTANCE
|
|
63
|
+
options: WebDuplexStreamOptions<TInput, TOutput>;
|
|
64
|
+
|
|
65
|
+
constructor(optionsArg: WebDuplexStreamOptions<TInput, TOutput>) {
|
|
66
|
+
super({
|
|
67
|
+
async transform(chunk, controller) {
|
|
68
|
+
// Transformation logic remains unchanged
|
|
69
|
+
if (optionsArg?.writeFunction) {
|
|
70
|
+
const tools: IStreamToolsWrite<TInput, TOutput> = {
|
|
71
|
+
truncate: () => controller.terminate(),
|
|
72
|
+
push: (pushArg: TOutput) => controller.enqueue(pushArg),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
optionsArg.writeFunction(chunk, tools)
|
|
76
|
+
.then(writeReturnChunk => {
|
|
77
|
+
// the write return chunk is optional
|
|
78
|
+
// just in case the write function returns something other than void.
|
|
79
|
+
if (writeReturnChunk) {
|
|
80
|
+
controller.enqueue(writeReturnChunk);
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
.catch(err => controller.error(err));
|
|
84
|
+
} else {
|
|
85
|
+
controller.error(new Error('No write function provided'));
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
async flush(controller) {
|
|
89
|
+
// Flush logic remains unchanged
|
|
90
|
+
if (optionsArg?.finalFunction) {
|
|
91
|
+
const tools: IStreamToolsWrite<TInput, TOutput> = {
|
|
92
|
+
truncate: () => controller.terminate(),
|
|
93
|
+
push: (pipeObject) => controller.enqueue(pipeObject),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
optionsArg.finalFunction(tools)
|
|
97
|
+
.then(finalChunk => {
|
|
98
|
+
if (finalChunk) {
|
|
99
|
+
controller.enqueue(finalChunk);
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
.catch(err => controller.error(err))
|
|
103
|
+
.finally(() => controller.terminate());
|
|
104
|
+
} else {
|
|
105
|
+
controller.terminate();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
this.options = optionsArg;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Method to create a custom readable stream that integrates the readFunction
|
|
114
|
+
// readFunction is executed whenever the stream is being read from and nothing is enqueued
|
|
115
|
+
getCustomReadableStream() {
|
|
116
|
+
const readableStream = this.readable;
|
|
117
|
+
const options = this.options;
|
|
118
|
+
const customReadable = new ReadableStream({
|
|
119
|
+
async pull(controller) {
|
|
120
|
+
const reader = readableStream.getReader();
|
|
121
|
+
|
|
122
|
+
// Check the current state of the original stream
|
|
123
|
+
const { value, done } = await reader.read();
|
|
124
|
+
reader.releaseLock();
|
|
125
|
+
|
|
126
|
+
if (done) {
|
|
127
|
+
// If the original stream is done, close the custom readable stream
|
|
128
|
+
controller.close();
|
|
129
|
+
} else {
|
|
130
|
+
if (value) {
|
|
131
|
+
// If there is data in the original stream, enqueue it and do not execute the readFunction
|
|
132
|
+
controller.enqueue(value);
|
|
133
|
+
} else if (options.readFunction) {
|
|
134
|
+
// If the original stream is empty, execute the readFunction and read again
|
|
135
|
+
await options.readFunction({
|
|
136
|
+
done: () => controller.close(),
|
|
137
|
+
write: (writeArg) => controller.enqueue(writeArg),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const newReader = readableStream.getReader();
|
|
141
|
+
const { value: newValue, done: newDone } = await newReader.read();
|
|
142
|
+
newReader.releaseLock();
|
|
143
|
+
|
|
144
|
+
if (newDone) {
|
|
145
|
+
controller.close();
|
|
146
|
+
} else {
|
|
147
|
+
controller.enqueue(newValue);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return customReadable;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface IDuplexStream {
|
|
2
|
+
read(): any;
|
|
3
|
+
write(chunk: any, callback?: (error?: Error | null) => void): boolean;
|
|
4
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
5
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
6
|
+
end(callback?: () => void): void;
|
|
7
|
+
destroy(error?: Error): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IReadableStreamOptions {
|
|
11
|
+
highWaterMark?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IWritableStreamOptions {
|
|
15
|
+
highWaterMark?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function convertDuplexToWebStream(duplex: IDuplexStream): { readable: ReadableStream, writable: WritableStream } {
|
|
19
|
+
const readable = new ReadableStream({
|
|
20
|
+
start(controller) {
|
|
21
|
+
duplex.on('readable', () => {
|
|
22
|
+
let chunk;
|
|
23
|
+
while (null !== (chunk = duplex.read())) {
|
|
24
|
+
controller.enqueue(chunk);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
duplex.on('end', () => {
|
|
29
|
+
controller.close();
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
cancel(reason) {
|
|
33
|
+
duplex.destroy(new Error(reason));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const writable = new WritableStream({
|
|
38
|
+
write(chunk) {
|
|
39
|
+
return new Promise<void>((resolve, reject) => {
|
|
40
|
+
const isBackpressured = !duplex.write(chunk, (error) => {
|
|
41
|
+
if (error) {
|
|
42
|
+
reject(error);
|
|
43
|
+
} else {
|
|
44
|
+
resolve();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (isBackpressured) {
|
|
49
|
+
duplex.once('drain', resolve);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
close() {
|
|
54
|
+
return new Promise<void>((resolve, reject) => {
|
|
55
|
+
duplex.end(resolve);
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
abort(reason) {
|
|
59
|
+
duplex.destroy(new Error(reason));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return { readable, writable };
|
|
64
|
+
}
|
package/ts_web/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @push.rocks scope
|
|
2
|
+
import * as smartenv from '@push.rocks/smartenv';
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
smartenv,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// lets setup dependencies
|
|
9
|
+
const smartenvInstance = new smartenv.Smartenv();
|
|
10
|
+
|
|
11
|
+
await smartenvInstance.getSafeNodeModule<typeof import('stream/web')>('stream/web', async (moduleArg) => {
|
|
12
|
+
globalThis.ReadableStream = moduleArg.ReadableStream;
|
|
13
|
+
globalThis.WritableStream = moduleArg.WritableStream;
|
|
14
|
+
globalThis.TransformStream = moduleArg.TransformStream;
|
|
15
|
+
})
|
package/assets/denoentry.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log('Hello from deno');
|