@push.rocks/smartstream 3.0.34 → 3.0.36

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.
@@ -0,0 +1 @@
1
+ console.log('Hello from deno');
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartstream',
6
- version: '3.0.34',
7
- description: 'simplifies access to node streams'
6
+ version: '3.0.36',
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
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx5QkFBeUI7SUFDL0IsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLG1DQUFtQztDQUNqRCxDQUFBIn0=
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx5QkFBeUI7SUFDL0IsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLHNMQUFzTDtDQUNwTSxDQUFBIn0=
@@ -2,3 +2,5 @@ export * from './smartstream.classes.smartduplex.js';
2
2
  export * from './smartstream.classes.streamwrapper.js';
3
3
  export * from './smartstream.classes.streamintake.js';
4
4
  export * from './smartstream.functions.js';
5
+ import * as plugins from './smartstream.plugins.js';
6
+ export declare const webstream: typeof plugins.webstream;
package/dist_ts/index.js CHANGED
@@ -2,4 +2,6 @@ export * from './smartstream.classes.smartduplex.js';
2
2
  export * from './smartstream.classes.streamwrapper.js';
3
3
  export * from './smartstream.classes.streamintake.js';
4
4
  export * from './smartstream.functions.js';
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHNDQUFzQyxDQUFDO0FBQ3JELGNBQWMsd0NBQXdDLENBQUM7QUFDdkQsY0FBYyx1Q0FBdUMsQ0FBQztBQUV0RCxjQUFjLDRCQUE0QixDQUFBIn0=
5
+ import * as plugins from './smartstream.plugins.js';
6
+ export const webstream = plugins.webstream;
7
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHNDQUFzQyxDQUFDO0FBQ3JELGNBQWMsd0NBQXdDLENBQUM7QUFDdkQsY0FBYyx1Q0FBdUMsQ0FBQztBQUV0RCxjQUFjLDRCQUE0QixDQUFDO0FBRTNDLE9BQU8sS0FBSyxPQUFPLE1BQU0sMEJBQTBCLENBQUM7QUFDcEQsTUFBTSxDQUFDLE1BQU0sU0FBUyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMifQ==
@@ -4,4 +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
- export { lik, smartpromise, smartrx };
7
+ import * as webstream from '@push.rocks/webstream';
8
+ export { lik, smartpromise, smartrx, webstream };
@@ -5,5 +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
- export { lik, smartpromise, smartrx };
9
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3RyZWFtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYztBQUNkLE9BQU8sS0FBSyxNQUFNLE1BQU0sUUFBUSxDQUFDO0FBRWpDLE9BQU8sRUFBRSxNQUFNLEVBQUUsQ0FBQztBQUVsQixrQkFBa0I7QUFDbEIsT0FBTyxLQUFLLEdBQUcsTUFBTSxpQkFBaUIsQ0FBQztBQUN2QyxPQUFPLEtBQUssWUFBWSxNQUFNLDBCQUEwQixDQUFDO0FBQ3pELE9BQU8sS0FBSyxPQUFPLE1BQU0scUJBQXFCLENBQUM7QUFFL0MsT0FBTyxFQUFFLEdBQUcsRUFBRSxZQUFZLEVBQUUsT0FBTyxFQUFFLENBQUMifQ==
8
+ import * as webstream from '@push.rocks/webstream';
9
+ export { lik, smartpromise, smartrx, webstream };
10
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3RyZWFtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYztBQUNkLE9BQU8sS0FBSyxNQUFNLE1BQU0sUUFBUSxDQUFDO0FBRWpDLE9BQU8sRUFBRSxNQUFNLEVBQUUsQ0FBQztBQUVsQixrQkFBa0I7QUFDbEIsT0FBTyxLQUFLLEdBQUcsTUFBTSxpQkFBaUIsQ0FBQztBQUN2QyxPQUFPLEtBQUssWUFBWSxNQUFNLDBCQUEwQixDQUFDO0FBQ3pELE9BQU8sS0FBSyxPQUFPLE1BQU0scUJBQXFCLENBQUM7QUFDL0MsT0FBTyxLQUFLLFNBQVMsTUFBTSx1QkFBdUIsQ0FBQztBQUVuRCxPQUFPLEVBQUUsR0FBRyxFQUFFLFlBQVksRUFBRSxPQUFPLEVBQUUsU0FBUyxFQUFFLENBQUMifQ==
package/npmextra.json CHANGED
@@ -6,12 +6,34 @@
6
6
  "gitzone": {
7
7
  "projectType": "npm",
8
8
  "module": {
9
- "githost": "gitlab.com",
9
+ "githost": "code.foss.global",
10
10
  "gitscope": "push.rocks",
11
11
  "gitrepo": "smartstream",
12
- "description": "simplifies access to node streams",
12
+ "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.",
13
13
  "npmPackagename": "@push.rocks/smartstream",
14
- "license": "MIT"
14
+ "license": "MIT",
15
+ "keywords": [
16
+ "stream",
17
+ "node.js",
18
+ "typescript",
19
+ "stream manipulation",
20
+ "data processing",
21
+ "pipeline",
22
+ "async transformation",
23
+ "event handling",
24
+ "backpressure",
25
+ "readable stream",
26
+ "writable stream",
27
+ "duplex stream",
28
+ "transform stream",
29
+ "file streaming",
30
+ "buffer",
31
+ "stream utilities",
32
+ "esm"
33
+ ]
15
34
  }
35
+ },
36
+ "tsdoc": {
37
+ "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
16
38
  }
17
39
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@push.rocks/smartstream",
3
- "version": "3.0.34",
3
+ "version": "3.0.36",
4
4
  "private": false,
5
- "description": "simplifies access to node streams",
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
6
  "main": "dist_ts/index.js",
7
7
  "typings": "dist_ts/index.d.ts",
8
8
  "type": "module",
@@ -27,7 +27,8 @@
27
27
  "dependencies": {
28
28
  "@push.rocks/lik": "^6.0.14",
29
29
  "@push.rocks/smartpromise": "^4.0.3",
30
- "@push.rocks/smartrx": "^3.0.7"
30
+ "@push.rocks/smartrx": "^3.0.7",
31
+ "@push.rocks/webstream": "^1.0.8"
31
32
  },
32
33
  "browserslist": [
33
34
  "last 1 chrome versions"
@@ -44,6 +45,25 @@
44
45
  "npmextra.json",
45
46
  "readme.md"
46
47
  ],
48
+ "keywords": [
49
+ "stream",
50
+ "node.js",
51
+ "typescript",
52
+ "stream manipulation",
53
+ "data processing",
54
+ "pipeline",
55
+ "async transformation",
56
+ "event handling",
57
+ "backpressure",
58
+ "readable stream",
59
+ "writable stream",
60
+ "duplex stream",
61
+ "transform stream",
62
+ "file streaming",
63
+ "buffer",
64
+ "stream utilities",
65
+ "esm"
66
+ ],
47
67
  "scripts": {
48
68
  "test": "(tstest test/)",
49
69
  "build": "(tsbuild)",
@@ -0,0 +1 @@
1
+ - make sure to respect backpressure handling.
package/readme.md CHANGED
@@ -1,54 +1,375 @@
1
- # @pushrocks/smartstream
2
- simplifies access to node streams
3
-
4
- ## Availabililty and Links
5
- * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartstream)
6
- * [gitlab.com (source)](https://gitlab.com/pushrocks/smartstream)
7
- * [github.com (source mirror)](https://github.com/pushrocks/smartstream)
8
- * [docs (typedoc)](https://pushrocks.gitlab.io/smartstream/)
9
-
10
- ## Status for master
11
-
12
- Status Category | Status Badge
13
- -- | --
14
- GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartstream/badges/master/pipeline.svg)](https://lossless.cloud)
15
- GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartstream/badges/master/coverage.svg)](https://lossless.cloud)
16
- npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartstream)](https://lossless.cloud)
17
- Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartstream)](https://lossless.cloud)
18
- TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
19
- node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
20
- Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
21
- PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartstream)](https://lossless.cloud)
22
- PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartstream)](https://lossless.cloud)
23
- BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartstream)](https://lossless.cloud)
24
- Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
1
+ ```markdown
2
+ # @push.rocks/smartstream
3
+ A TypeScript library to simplify the creation and manipulation of Node.js streams, providing utilities for transform, duplex, and readable/writable stream handling while managing backpressure effectively.
4
+
5
+ ## Install
6
+ To install `@push.rocks/smartstream`, you can use npm or yarn as follows:
7
+
8
+ ```bash
9
+ npm install @push.rocks/smartstream --save
10
+ # OR
11
+ yarn add @push.rocks/smartstream
12
+ ```
13
+
14
+ This will add `@push.rocks/smartstream` to your project's dependencies.
25
15
 
26
16
  ## Usage
27
17
 
28
- Use TypeScript for best in class instellisense.
18
+ The `@push.rocks/smartstream` module is designed to simplify working with Node.js streams by providing a set of utilities for creating and manipulating streams. This module makes extensive use of TypeScript for improved code quality, readability, and maintenance. ESM syntax is utilized throughout the examples.
19
+
20
+ ### Importing the Module
21
+
22
+ Start by importing the module into your TypeScript file:
23
+
24
+ ```typescript
25
+ import * as smartstream from '@push.rocks/smartstream';
26
+ ```
27
+
28
+ For a more specific import, you may do the following:
29
+
30
+ ```typescript
31
+ import { SmartDuplex, StreamWrapper, StreamIntake, createTransformFunction, createPassThrough } from '@push.rocks/smartstream';
32
+ ```
33
+
34
+ ### Creating Basic Transform Streams
35
+
36
+ The module provides utilities for creating transform streams. For example, to create a transform stream that modifies chunks of data, you can use the `createTransformFunction` utility:
37
+
38
+ ```typescript
39
+ import { createTransformFunction } from '@push.rocks/smartstream';
40
+
41
+ const upperCaseTransform = createTransformFunction<string, string>(async (chunk) => {
42
+ return chunk.toUpperCase();
43
+ });
44
+
45
+ // Usage with pipe
46
+ readableStream
47
+ .pipe(upperCaseTransform)
48
+ .pipe(writableStream);
49
+ ```
50
+
51
+ ### Handling Backpressure with SmartDuplex
52
+
53
+ `SmartDuplex` is a powerful part of the `smartstream` module designed to handle backpressure effectively. Here's an example of how to create a `SmartDuplex` stream that processes data and respects the consumer's pace:
54
+
55
+ ```typescript
56
+ import { SmartDuplex } from '@push.rocks/smartstream';
57
+
58
+ const processDataDuplex = new SmartDuplex({
59
+ async writeFunction(chunk, { push }) {
60
+ const processedChunk = await processChunk(chunk); // Assume this is a defined asynchronous function
61
+ push(processedChunk);
62
+ }
63
+ });
64
+
65
+ sourceStream.pipe(processDataDuplex).pipe(destinationStream);
66
+ ```
67
+
68
+ ### Combining Multiple Streams
69
+
70
+ `Smartstream` facilitates easy combining of multiple streams into a single pipeline, handling errors and cleanup automatically. Here's how you can combine multiple streams:
29
71
 
30
72
  ```typescript
31
- import { Smartstream } from 'smartstream'
32
- import * as gUglify from 'gulp-uglify'
73
+ import { StreamWrapper } from '@push.rocks/smartstream';
33
74
 
34
- let mySmartstream = new Smartstream([
35
- gulp.src(['./file1.js','./file2.js']),
36
- gUglify(),
37
- gulp.dest('./some/output/path')
38
- ])
75
+ const combinedStream = new StreamWrapper([
76
+ readStream, // Source stream
77
+ transformStream1, // Transformation
78
+ transformStream2, // Another transformation
79
+ writeStream // Destination stream
80
+ ]);
39
81
 
40
- mySmartstream.onError((err) => { /* handle error */ }) // handles all errors in stream
41
- myStream.onCustomEvent('myeventname', (args...) => { /* Do something */ }) // emit an custom event anywhere in your stream
42
- mySmartstream.run().then(() => {/* do something when stream is finished */})
82
+ combinedStream.run()
83
+ .then(() => console.log('Processing completed.'))
84
+ .catch(err => console.error('An error occurred:', err));
43
85
  ```
44
86
 
45
- ## Contribution
87
+ ### Working with StreamIntake
88
+
89
+ `StreamIntake` allows for more dynamic control of the reading process, facilitating scenarios where data is not continuously available:
90
+
91
+ ```typescript
92
+ import { StreamIntake } from '@push.rocks/smartstream';
93
+
94
+ const streamIntake = new StreamIntake<string>();
95
+
96
+ // Dynamically push data into the intake
97
+ streamIntake.pushData('Hello, World!');
98
+ streamIntake.pushData('Another message');
99
+
100
+ // Signal end when no more data is to be pushed
101
+ streamIntake.signalEnd();
102
+ ```
103
+
104
+ ### Real-world Scenario: Processing Large Files
105
+
106
+ Consider a scenario where you need to process a large CSV file, transform the data row-by-row, and then write the results to a database or another file. With `smartstream`, you could create a pipe that reads the CSV, processes each row, and handles backpressure, ensuring efficient use of resources.
107
+
108
+ ```typescript
109
+ import { SmartDuplex, createTransformFunction } from '@push.rocks/smartstream';
110
+ import fs from 'fs';
111
+ import csvParser from 'csv-parser';
112
+
113
+ const csvReadTransform = createTransformFunction<any, any>(async (row) => {
114
+ // Process row
115
+ return processedRow;
116
+ });
117
+
118
+ fs.createReadStream('path/to/largeFile.csv')
119
+ .pipe(csvParser())
120
+ .pipe(csvReadTransform)
121
+ .pipe(new SmartDuplex({
122
+ async writeFunction(chunk, { push }) {
123
+ await writeToDatabase(chunk); // Assume this writes to a database
124
+ }
125
+ }))
126
+ .on('finish', () => console.log('File processed successfully.'));
127
+ ```
128
+
129
+ This example demonstrates reading a large CSV file, transforming each row with `createTransformFunction`, and using a `SmartDuplex` to manage the processed data flow efficiently, ensuring no data is lost due to backpressure issues.
130
+
131
+ ### Advanced Use Case: Backpressure Handling
132
+
133
+ Effective backpressure handling is crucial when working with streams to avoid overwhelming the downstream consumers. Here’s a comprehensive example that demonstrates handling backpressure in a pipeline with multiple `SmartDuplex` instances:
134
+
135
+ ```typescript
136
+ import { SmartDuplex } from '@push.rocks/smartstream';
137
+
138
+ // Define the first SmartDuplex, which writes data slowly to simulate backpressure
139
+ const slowProcessingStream = new SmartDuplex({
140
+ name: 'SlowProcessor',
141
+ objectMode: true,
142
+ writeFunction: async (chunk, { push }) => {
143
+ await new Promise(resolve => setTimeout(resolve, 100)); // Simulated delay
144
+ console.log('Processed chunk:', chunk);
145
+ push(chunk);
146
+ }
147
+ });
148
+
149
+ // Define the second SmartDuplex as a fast processor
150
+ const fastProcessingStream = new SmartDuplex({
151
+ name: 'FastProcessor',
152
+ objectMode: true,
153
+ writeFunction: async (chunk, { push }) => {
154
+ console.log('Fast processing chunk:', chunk);
155
+ push(chunk);
156
+ }
157
+ });
158
+
159
+ // Create a StreamIntake to dynamically handle incoming data
160
+ const streamIntake = new StreamIntake<string>();
161
+
162
+ // Chain the streams together and handle the backpressure scenario
163
+ streamIntake
164
+ .pipe(fastProcessingStream)
165
+ .pipe(slowProcessingStream)
166
+ .pipe(createPassThrough()) // Use Pass-Through to provide intermediary handling
167
+ .on('data', data => console.log('Final output:', data))
168
+ .on('error', error => console.error('Stream encountered an error:', error));
169
+
170
+ // Simulate data pushing with intervals to observe backpressure handling
171
+ let counter = 0;
172
+ const interval = setInterval(() => {
173
+ if (counter >= 10) {
174
+ streamIntake.signalEnd();
175
+ clearInterval(interval);
176
+ } else {
177
+ streamIntake.pushData(`Chunk ${counter}`);
178
+ counter++;
179
+ }
180
+ }, 50);
181
+ ```
182
+
183
+ In this advanced use case, a `SlowProcessor` and `FastProcessor` are created using `SmartDuplex`, simulating a situation where one stream is slower than another. The `StreamIntake` dynamically handles incoming chunks of data and the intermediary Pass-Through handles any potential interruptions.
184
+
185
+ ### Transform Streams in Parallel
186
+
187
+ For scenarios where you need to process data in parallel:
188
+
189
+ ```typescript
190
+ import { SmartDuplex, createTransformFunction } from '@push.rocks/smartstream';
191
+
192
+ const parallelTransform = createTransformFunction<any, any>(async (chunk) => {
193
+ // Parallel Processing
194
+ const results = await Promise.all(chunk.map(async item => await processItem(item)));
195
+ return results;
196
+ });
197
+
198
+ const streamIntake = new StreamIntake<any[]>();
199
+
200
+ streamIntake
201
+ .pipe(parallelTransform)
202
+ .pipe(new SmartDuplex({
203
+ async writeFunction(chunk, { push }) {
204
+ console.log('Processed parallel chunk:', chunk);
205
+ push(chunk);
206
+ }
207
+ }))
208
+ .on('finish', () => console.log('Parallel processing completed.'));
209
+
210
+ // Simulate data pushing
211
+ streamIntake.pushData([1, 2, 3, 4]);
212
+ streamIntake.pushData([5, 6, 7, 8]);
213
+ streamIntake.signalEnd();
214
+ ```
215
+
216
+ ### Error Handling in Stream Pipelines
217
+
218
+ Error handling is an essential part of working with streams. The `StreamWrapper` assists in combining multiple streams while managing errors seamlessly:
219
+
220
+ ```typescript
221
+ import { StreamWrapper } from '@push.rocks/smartstream';
222
+
223
+ const faultyStream = new SmartDuplex({
224
+ async writeFunction(chunk, { push }) {
225
+ if (chunk === 'bad data') {
226
+ throw new Error('Faulty data encountered');
227
+ }
228
+ push(chunk);
229
+ }
230
+ });
231
+
232
+ const readStream = new StreamIntake<string>();
233
+ const writeStream = new SmartDuplex({
234
+ async writeFunction(chunk) {
235
+ console.log('Written chunk:', chunk);
236
+ }
237
+ });
238
+
239
+ const combinedStream = new StreamWrapper([readStream, faultyStream, writeStream]);
240
+
241
+ combinedStream.run()
242
+ .then(() => console.log('Stream processing completed.'))
243
+ .catch(err => console.error('Stream error:', err.message));
244
+
245
+ // Push Data
246
+ readStream.pushData('good data');
247
+ readStream.pushData('bad data'); // This will throw an error
248
+ readStream.pushData('more good data');
249
+ readStream.signalEnd();
250
+ ```
251
+
252
+ ### Testing Streams
253
+
254
+ Here's an example test case using the `tap` testing framework to verify the integrity of the `SmartDuplex` from a buffer:
255
+
256
+ ```typescript
257
+ import { expect, tap } from '@push.rocks/tapbundle';
258
+ import { SmartDuplex } from '@push.rocks/smartstream';
259
+
260
+ tap.test('should create a SmartStream from a Buffer', async () => {
261
+ const bufferData = Buffer.from('This is a test buffer');
262
+ const smartStream = SmartDuplex.fromBuffer(bufferData, {});
263
+
264
+ let receivedData = Buffer.alloc(0);
265
+
266
+ return new Promise<void>((resolve) => {
267
+ smartStream.on('data', (chunk: Buffer) => {
268
+ receivedData = Buffer.concat([receivedData, chunk]);
269
+ });
270
+
271
+ smartStream.on('end', () => {
272
+ expect(receivedData.toString()).toEqual(bufferData.toString());
273
+ resolve();
274
+ });
275
+ });
276
+ });
277
+
278
+ tap.start();
279
+ ```
280
+
281
+ ### Working with Files and Buffers
282
+
283
+ You can easily stream files and buffers with `smartstream`. Here’s a test illustrating reading and writing with file streams using `smartfile` combined with `smartstream` utilities:
284
+
285
+ ```typescript
286
+ import { tap } from '@push.rocks/tapbundle';
287
+ import * as smartfile from '@push.rocks/smartfile';
288
+ import { SmartDuplex, StreamWrapper } from '@push.rocks/smartstream';
289
+
290
+ tap.test('should handle file read and write streams', async () => {
291
+ const readStream = smartfile.fsStream.createReadStream('./test/assets/readabletext.txt');
292
+ const writeStream = smartfile.fsStream.createWriteStream('./test/assets/writabletext.txt');
293
+
294
+ const transformStream = new SmartDuplex({
295
+ async writeFunction(chunk, { push }) {
296
+ const transformedChunk = chunk.toString().toUpperCase();
297
+ push(transformedChunk);
298
+ }
299
+ });
300
+
301
+ const streamWrapper = new StreamWrapper([readStream, transformStream, writeStream]);
302
+
303
+ await streamWrapper.run();
304
+
305
+ const outputContent = await smartfile.fs.promises.readFile('./test/assets/writabletext.txt', 'utf-8');
306
+ console.log('Output Content:', outputContent);
307
+ });
308
+
309
+ tap.start();
310
+ ```
311
+
312
+ ### Modular and Scoped Transformations
313
+
314
+ Creating modular and scoped transformations is straightforward with `SmartDuplex`:
315
+
316
+ ```typescript
317
+ import { SmartDuplex } from '@push.rocks/smartstream';
318
+
319
+ type DataChunk = {
320
+ id: number;
321
+ data: string;
322
+ };
323
+
324
+ const transformationStream1 = new SmartDuplex<DataChunk, DataChunk>({
325
+ async writeFunction(chunk, { push }) {
326
+ chunk.data = chunk.data.toUpperCase();
327
+ push(chunk);
328
+ }
329
+ })
330
+
331
+ const transformationStream2 = new SmartDuplex<DataChunk, DataChunk>({
332
+ async writeFunction(chunk, { push }) {
333
+ chunk.data = `${chunk.data} processed with transformation 2`;
334
+ push(chunk);
335
+ }
336
+ });
337
+
338
+ const initialData: DataChunk[] = [
339
+ { id: 1, data: 'first' },
340
+ { id: 2, data: 'second' }
341
+ ];
342
+
343
+ const intakeStream = new StreamIntake<DataChunk>();
344
+
345
+ intakeStream
346
+ .pipe(transformationStream1)
347
+ .pipe(transformationStream2)
348
+ .on('data', data => console.log('Transformed Data:', data));
349
+
350
+ initialData.forEach(item => intakeStream.pushData(item));
351
+ intakeStream.signalEnd();
352
+ ```
353
+
354
+ By leveraging `SmartDuplex`, `StreamWrapper`, and `StreamIntake`, you can streamline and enhance your data transformation pipelines in Node.js with a clear, efficient, and backpressure-friendly approach.
355
+ ```
356
+
357
+
358
+ ## License and Legal Information
359
+
360
+ This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
361
+
362
+ **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
363
+
364
+ ### Trademarks
365
+
366
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
46
367
 
47
- We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
368
+ ### Company Information
48
369
 
49
- For further information read the linked docs at the top of this readme.
370
+ Task Venture Capital GmbH
371
+ Registered at District court Bremen HRB 35230 HB, Germany
50
372
 
51
- > MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
52
- | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
373
+ For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
53
374
 
54
- [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
375
+ By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartstream',
6
- version: '3.0.34',
7
- description: 'simplifies access to node streams'
6
+ version: '3.0.36',
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
  }
package/ts/index.ts CHANGED
@@ -2,4 +2,7 @@ export * from './smartstream.classes.smartduplex.js';
2
2
  export * from './smartstream.classes.streamwrapper.js';
3
3
  export * from './smartstream.classes.streamintake.js';
4
4
 
5
- export * from './smartstream.functions.js'
5
+ export * from './smartstream.functions.js';
6
+
7
+ import * as plugins from './smartstream.plugins.js';
8
+ export const webstream = plugins.webstream;
@@ -7,6 +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 '@push.rocks/webstream';
10
11
 
11
- export { lik, smartpromise, smartrx };
12
+ export { lik, smartpromise, smartrx, webstream };
12
13