Compare commits

...

34 Commits

Author SHA1 Message Date
41eed6423d 2.0.3 2022-06-07 18:32:08 +02:00
0e067004a4 fix(core): update 2022-06-07 18:32:08 +02:00
9fe222b500 2.0.2 2022-06-07 16:16:15 +02:00
05e9067a34 fix(core): update 2022-06-07 16:16:14 +02:00
2aff46eb0e 2.0.1 2022-03-31 01:20:20 +02:00
6aa4b86598 fix(core): update 2022-03-31 01:20:20 +02:00
af30268551 2.0.0 2022-03-31 01:20:01 +02:00
e562e8f099 BREAKING CHANGE(core): switch to esm 2022-03-31 01:20:01 +02:00
01f4a53b5b 1.0.14 2019-02-20 23:18:21 +01:00
f42b77986f fix(structure): cleanup 2019-02-20 23:18:20 +01:00
b7ef295757 1.0.13 2019-02-20 00:40:32 +01:00
2818420ee9 fix(docs): update 2019-02-20 00:40:31 +01:00
d759e2a562 1.0.12 2019-02-19 01:10:56 +01:00
65a97c9ee0 fix(core): update 2019-02-19 01:10:56 +01:00
b036bfcb92 1.0.11 2017-07-07 02:46:22 +02:00
c0304d1d10 update README 2017-07-07 02:46:20 +02:00
26880f9b71 1.0.10 2017-06-30 18:37:51 +02:00
aa7c30a096 update ci 2017-06-30 18:37:48 +02:00
083673f02c 1.0.9 2017-06-30 18:32:34 +02:00
93bcc03e72 update smartstream 2017-06-30 18:32:32 +02:00
f8b79710be 1.0.8 2017-03-04 14:26:10 +01:00
addf20995a fix cleanPipe() 2017-03-04 14:26:10 +01:00
5401e5e008 1.0.7 2017-03-04 13:53:21 +01:00
144295f7c0 update ci 2017-03-04 13:53:18 +01:00
1e0557b722 1.0.6 2017-03-04 13:50:15 +01:00
9b67507acd add cleanPipe() 2017-03-04 13:50:12 +01:00
c7b3f2a228 1.0.5 2016-09-25 19:41:15 +02:00
084a47096d switch to done.reject for error handling 2016-09-25 19:41:12 +02:00
224b39f0a6 1.0.4 2016-09-25 16:28:45 +02:00
b24b564495 improved README 2016-09-25 16:28:42 +02:00
aabfb2721d 1.0.3 2016-09-25 16:10:11 +02:00
c28e2cb8e0 now allows the handling of custom events and run returns promise 2016-09-25 16:10:06 +02:00
aaece166c0 1.0.2 2016-09-25 14:01:55 +02:00
6380998fcf fix filename for gitlab ci 2016-09-25 14:01:50 +02:00
28 changed files with 17988 additions and 167 deletions

20
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
public/
pages/
coverage/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

140
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,140 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -1,9 +0,0 @@
# smartstream
simplifies access to node streams, TypeScript ready!
## Status
[![build status](https://gitlab.com/pushrocks/smartstream/badges/master/build.svg)](https://gitlab.com/pushrocks/smartstream/commits/master)
## Usage
We recommend the use of TypeScript for best in class intellisense support.

10
dist/index.d.ts vendored
View File

@ -1,10 +0,0 @@
export interface IErrorFunction {
(err: any): number;
}
export declare class Smartstream {
streamArray: any[];
errorFunction: IErrorFunction;
constructor(streamArrayArg: any[]);
onError(errorFunctionArg: IErrorFunction): void;
run(): any;
}

21
dist/index.js vendored
View File

@ -1,21 +0,0 @@
"use strict";
const plugins = require("./smartstream.plugins");
class Smartstream {
constructor(streamArrayArg) {
this.streamArray = [];
this.errorFunction = null;
this.streamArray = streamArrayArg;
}
onError(errorFunctionArg) {
this.errorFunction = errorFunctionArg;
}
run() {
let combinedStream = plugins.streamCombiner2.obj(this.streamArray);
if (this.errorFunction !== null) {
combinedStream.on('error', this.errorFunction);
}
return combinedStream;
}
}
exports.Smartstream = Smartstream;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsaURBQWdEO0FBTWhEO0lBR0ksWUFBWSxjQUFxQjtRQUZqQyxnQkFBVyxHQUFHLEVBQUUsQ0FBQTtRQUNoQixrQkFBYSxHQUFtQixJQUFJLENBQUE7UUFFaEMsSUFBSSxDQUFDLFdBQVcsR0FBRyxjQUFjLENBQUE7SUFDckMsQ0FBQztJQUNELE9BQU8sQ0FBQyxnQkFBZ0M7UUFDcEMsSUFBSSxDQUFDLGFBQWEsR0FBRyxnQkFBZ0IsQ0FBQTtJQUN6QyxDQUFDO0lBQ0QsR0FBRztRQUNDLElBQUksY0FBYyxHQUFHLE9BQU8sQ0FBQyxlQUFlLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtRQUNsRSxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsYUFBYSxLQUFLLElBQUksQ0FBQyxDQUFDLENBQUM7WUFDOUIsY0FBYyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUUsSUFBSSxDQUFDLGFBQWEsQ0FBQyxDQUFBO1FBQ2xELENBQUM7UUFDRCxNQUFNLENBQUMsY0FBYyxDQUFBO0lBQ3pCLENBQUM7Q0FDSjtBQWhCRCxrQ0FnQkMifQ==

View File

@ -1,3 +0,0 @@
import 'typings-global';
export import q = require('q');
export declare let streamCombiner2: any;

View File

@ -1,5 +0,0 @@
"use strict";
require("typings-global");
exports.q = require("q");
exports.streamCombiner2 = require('stream-combiner2');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3RyZWFtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix5QkFBOEI7QUFDbkIsUUFBQSxlQUFlLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUEifQ==

View File

@ -1,42 +0,0 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- page
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: page
script:
- npmci command npmpage --host gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public

View File

@ -1 +1,17 @@
{}
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartstream",
"description": "simplifies access to node streams",
"npmPackagename": "@pushrocks/smartstream",
"license": "MIT"
}
}
}

11052
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,14 @@
{
"name": "smartstream",
"version": "1.0.1",
"description": "simplifies access to node streams, TypeScript ready!",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "@pushrocks/smartstream",
"version": "2.0.3",
"private": false,
"description": "simplifies access to node streams",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -18,15 +21,34 @@
},
"homepage": "https://gitlab.com/pushrocks/smartstream#README",
"devDependencies": {
"@types/should": "^8.1.30",
"npmts-g": "^5.2.8",
"should": "^11.1.0",
"typings-test": "^1.0.3"
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tstest": "^1.0.71",
"@pushrocks/smartfile": "^10.0.0",
"@pushrocks/tapbundle": "^5.0.3",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@types/q": "0.x.x",
"q": "^1.4.1",
"stream-combiner2": "^1.1.1",
"typings-global": "^1.0.14"
}
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrx": "^2.0.25",
"@types/from2": "^2.3.1",
"@types/through2": "^2.0.36",
"from2": "^2.3.0",
"through2": "^4.0.2"
},
"browserslist": [
"last 1 chrome versions"
],
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

54
readme.md Normal file
View File

@ -0,0 +1,54 @@
# @pushrocks/smartstream
simplifies access to node streams
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartstream)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartstream)
* [github.com (source mirror)](https://github.com/pushrocks/smartstream)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstream/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartstream/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartstream/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartstream)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartstream)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartstream)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartstream)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartstream)](https://lossless.cloud)
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)
## Usage
Use TypeScript for best in class instellisense.
```typescript
import { Smartstream } from 'smartstream'
import * as gUglify from 'gulp-uglify'
let mySmartstream = new Smartstream([
gulp.src(['./file1.js','./file2.js']),
gUglify(),
gulp.dest('./some/output/path')
])
mySmartstream.onError((err) => { /* handle error */ }) // handles all errors in stream
myStream.onCustomEvent('myeventname', (args...) => { /* Do something */ }) // emit an custom event anywhere in your stream
mySmartstream.run().then(() => {/* do something when stream is finished */})
```
## Contribution
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). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

6210
test/assets/readabletext.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
hi+wow
noice

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,15 +0,0 @@
"use strict";
require("typings-test");
const fs = require("fs");
const smartstream = require("../dist/index");
let testSmartstream;
describe('smartstream', function () {
it('should combine a stream', function () {
testSmartstream = new smartstream.Smartstream([
fs.createReadStream('./test/assets/test.md'),
fs.createWriteStream('./test/assets/testCopy.md')
]);
testSmartstream.run();
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQix5QkFBeUI7QUFHekIsNkNBQTRDO0FBRTVDLElBQUksZUFBd0MsQ0FBQTtBQUU1QyxRQUFRLENBQUMsYUFBYSxFQUFFO0lBQ3BCLEVBQUUsQ0FBQyx5QkFBeUIsRUFBRTtRQUMxQixlQUFlLEdBQUcsSUFBSSxXQUFXLENBQUMsV0FBVyxDQUFDO1lBQzFDLEVBQUUsQ0FBQyxnQkFBZ0IsQ0FBQyx1QkFBdUIsQ0FBQztZQUM1QyxFQUFFLENBQUMsaUJBQWlCLENBQUMsMkJBQTJCLENBQUM7U0FDcEQsQ0FBQyxDQUFBO1FBQ0YsZUFBZSxDQUFDLEdBQUcsRUFBRSxDQUFBO0lBQ3pCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -0,0 +1,68 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartfile from '@pushrocks/smartfile';
import * as smartstream from '../ts/index.js';
let testIntake: smartstream.StreamIntake<string>;
tap.test('should handle a read stream', async (tools) => {
const counter = 0;
const testSmartstream = new smartstream.StreamWrapper([
smartfile.fsStream.createReadStream('./test/assets/readabletext.txt'),
smartstream.createDuplexStream<Buffer, Buffer>(
async (chunkStringArg: Buffer, streamTools) => {
// do something with the stream here
const result = chunkStringArg.toString().substr(0, 100);
streamTools.pipeMore('wow =========== \n');
return Buffer.from(result);
},
async (tools) => {
// tools.pipeMore('hey, this is the end')
return Buffer.from('this is the end');
},
{ objectMode: false }
),
smartstream.createDuplexStream<Buffer, string>(async (chunkStringArg) => {
console.log(chunkStringArg.toString());
return null;
}),
smartstream.cleanPipe(),
]);
await testSmartstream.run();
});
tap.test('should create a valid Intake', async (tools) => {
testIntake = new smartstream.StreamIntake<string>();
testIntake
.getReadable()
.pipe(
smartstream.createDuplexStream<string, string>(
async (chunkString) => {
await tools.delayFor(100);
console.log(chunkString);
return chunkString;
},
async () => {
return 'noice';
}
)
)
.pipe(smartfile.fsStream.createWriteStream('./test/assets/writabletext.txt'));
const testFinished = tools.defer();
let counter = 0;
testIntake.pushNextObservable.subscribe(() => {
if (counter < 50) {
counter++;
testIntake.pushData('hi');
testIntake.pushData('+wow');
testIntake.pushData('\n');
} else {
testIntake.signalEnd();
testFinished.resolve();
}
});
await testFinished.promise;
testIntake.signalEnd();
});
tap.start();

View File

@ -1,17 +1,15 @@
import 'typings-test'
import fs = require('fs')
import * as should from 'should'
import * as smartfile from '@pushrocks/smartfile';
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartstream from '../dist/index'
import * as smartstream from '../ts/smartstream.classes.streamwrapper.js';
let testSmartstream: smartstream.Smartstream
let testSmartstream: smartstream.StreamWrapper;
tap.test('should combine a stream', async () => {
testSmartstream = new smartstream.StreamWrapper([
smartfile.fsStream.createReadStream('./test/assets/test.md'),
smartfile.fsStream.createWriteStream('./test/assets/testCopy.md'),
]);
await testSmartstream.run();
});
describe('smartstream', function() {
it('should combine a stream', function(){
testSmartstream = new smartstream.Smartstream([
fs.createReadStream('./test/assets/test.md'),
fs.createWriteStream('./test/assets/testCopy.md')
])
testSmartstream.run()
})
})
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartstream',
version: '2.0.3',
description: 'simplifies access to node streams'
}

View File

@ -1,23 +1,3 @@
import * as plugins from './smartstream.plugins'
export interface IErrorFunction {
(err): number
}
export class Smartstream {
streamArray = []
errorFunction: IErrorFunction = null
constructor(streamArrayArg: any[]){
this.streamArray = streamArrayArg
}
onError(errorFunctionArg: IErrorFunction) {
this.errorFunction = errorFunctionArg
}
run() {
let combinedStream = plugins.streamCombiner2.obj(this.streamArray)
if (this.errorFunction !== null) {
combinedStream.on('error', this.errorFunction)
}
return combinedStream
}
}
export * from './smartstream.classes.streamwrapper.js';
export * from './smartstream.classes.streamintake.js';
export * from './smartstream.duplex.js';

View File

@ -0,0 +1,66 @@
import * as plugins from './smartstream.plugins.js';
export class StreamIntake<T> {
private signalEndBoolean = false;
private chunkStore: T[] = [];
public pushNextObservable = new plugins.smartrx.ObservableIntake<any>();
private pushedNextDeferred = plugins.smartpromise.defer();
private readableStream = plugins.from2.obj(async (size, next) => {
// console.log('get next');
// execute without backpressure
while (this.chunkStore.length > 0) {
next(null, this.chunkStore.shift());
}
if (this.signalEndBoolean) {
next(null, null);
}
// lets trigger backpressure handling
this.pushNextObservable.push('please push next');
await this.pushedNextDeferred.promise;
this.pushedNextDeferred = plugins.smartpromise.defer();
// execute with backpressure
while (this.chunkStore.length > 0) {
next(null, this.chunkStore.shift());
}
if (this.signalEndBoolean) {
next(null, null);
}
});
constructor() {
this.pushNextObservable.push('please push next');
}
/**
* returns a new style readble stream
*/
public getReadable() {
const readable = new plugins.stream.Readable({
objectMode: true,
});
return readable.wrap(this.readableStream);
}
/**
* returns an oldstyle readble stream
*/
public getReadableStream() {
return this.readableStream;
}
public pushData(chunkData: T) {
this.chunkStore.push(chunkData);
this.pushedNextDeferred.resolve();
}
public signalEnd() {
this.signalEndBoolean = true;
this.pushedNextDeferred.resolve();
this.pushNextObservable.signalComplete();
}
}

View File

@ -0,0 +1,107 @@
import * as plugins from './smartstream.plugins.js';
// interfaces
import { Transform } from 'stream';
export interface IErrorFunction {
(err: Error): any;
}
export interface ICustomEventFunction {
(): any;
}
export interface ICustomEventObject {
eventName: string;
eventFunction: ICustomEventFunction;
}
/**
* class Smartstream handles
*/
export class StreamWrapper {
private streamArray: Array<plugins.stream.Duplex> = [];
private customEventObjectArray: ICustomEventObject[] = [];
private streamStartedDeferred = plugins.smartpromise.defer();
/**
* constructor
*/
constructor(streamArrayArg: any[]) {
this.streamArray = streamArrayArg;
}
/**
* make something with the stream itself
*/
streamStarted(): Promise<any> {
return this.streamStartedDeferred.promise;
}
/**
* attach listener to custom event
*/
onCustomEvent(eventNameArg: string, eventFunctionArg: ICustomEventFunction) {
this.customEventObjectArray.push({
eventName: eventNameArg,
eventFunction: eventFunctionArg,
});
}
/**
* run the stream
* @returns Promise
*/
run(): Promise<void> {
const done = plugins.smartpromise.defer<void>();
// clone Array
const streamExecutionArray: Array<plugins.stream.Duplex> = [];
for (const streamItem of this.streamArray) {
streamExecutionArray.push(streamItem);
}
// combine the stream
let finalStream = null;
let firstIteration: boolean = true;
for (const stream of streamExecutionArray) {
if (firstIteration === true) {
finalStream = stream;
}
stream.on('error', (err) => {
done.reject(err);
});
for (const customEventObject of this.customEventObjectArray) {
stream.on(customEventObject.eventName, customEventObject.eventFunction);
}
if (!firstIteration) {
finalStream = finalStream.pipe(stream);
}
firstIteration = false;
}
this.streamStartedDeferred.resolve();
finalStream.on('end', () => {
done.resolve();
});
finalStream.on('close', () => {
done.resolve();
});
finalStream.on('finish', () => {
done.resolve();
});
return done.promise;
}
}
export let cleanPipe = () => {
return plugins.through2.obj(
(file, enc, cb) => {
cb();
},
(cb) => {
cb();
}
);
};

83
ts/smartstream.duplex.ts Normal file
View File

@ -0,0 +1,83 @@
import * as plugins from './smartstream.plugins.js';
export interface ITruncateFunc {
(): void;
}
export interface IPipeMoreFunc {
(pipeObject: any): void;
}
export interface IStreamTools {
truncate: ITruncateFunc;
pipeMore: IPipeMoreFunc;
}
export interface IStreamFunction<T, rT> {
(chunkArg: T, toolsArg: IStreamTools): Promise<rT>;
}
export interface IStreamEndFunction<rT> {
(toolsArg: IStreamTools): Promise<rT>;
}
export interface IStreamOptions {
objectMode?: boolean;
readableObjectMode?: boolean;
writableObjectMode?: boolean;
}
export let createDuplexStream = <T, rT>(
funcArg: IStreamFunction<T, rT>,
endFuncArg?: IStreamEndFunction<rT>,
optionsArg: IStreamOptions = {
objectMode: false,
readableObjectMode: true,
writableObjectMode: true,
}
) => {
return plugins.through2(
optionsArg,
function (chunk, enc, cb) {
let truncated = false;
const tools: IStreamTools = {
truncate: () => {
truncated = true;
cb(null, null);
},
pipeMore: (pipeObject) => {
this.push(pipeObject);
},
};
const asyncWrapper = async () => {
const resultChunk: rT = await funcArg(chunk, tools);
if (!truncated) {
cb(null, resultChunk);
}
};
asyncWrapper().catch((err) => {
console.log(err);
});
},
function (cb) {
const tools: IStreamTools = {
truncate: () => {
cb();
},
pipeMore: (pushArg) => {
this.push(pushArg);
},
};
const asyncWrapper = async () => {
if (endFuncArg) {
const result = await endFuncArg(tools);
this.push(result);
}
cb();
};
asyncWrapper().catch((err) => {
console.log(err);
});
}
);
};

View File

@ -1,3 +1,16 @@
import 'typings-global'
export import q = require('q')
export let streamCombiner2 = require('stream-combiner2')
// node native
import * as stream from 'stream';
export { stream };
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
export { smartpromise, smartrx };
// thirdparty
import from2 from 'from2';
import through2 from 'through2';
export { from2, through2 };

9
tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
}

View File

@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}