Compare commits

..

6 Commits

Author SHA1 Message Date
15a226d30d 2.0.5 2023-11-01 14:16:59 +01:00
16c5c89662 fix(core): update 2023-11-01 14:16:58 +01:00
851a96c014 2.0.4 2023-07-12 11:27:47 +02:00
4ea42cb9fb fix(core): update 2023-07-12 11:27:46 +02:00
41eed6423d 2.0.3 2022-06-07 18:32:08 +02:00
0e067004a4 fix(core): update 2022-06-07 18:32:08 +02:00
13 changed files with 5837 additions and 11080 deletions

View File

@ -123,7 +123,7 @@ pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci command npm install -g @git.zone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc

View File

@ -7,10 +7,10 @@
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitscope": "push.rocks",
"gitrepo": "smartstream",
"description": "simplifies access to node streams",
"npmPackagename": "@pushrocks/smartstream",
"npmPackagename": "@push.rocks/smartstream",
"license": "MIT"
}
}

11052
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartstream",
"version": "2.0.2",
"name": "@push.rocks/smartstream",
"version": "2.0.5",
"private": false,
"description": "simplifies access to node streams",
"main": "dist_ts/index.js",
@ -21,18 +21,17 @@
},
"homepage": "https://gitlab.com/pushrocks/smartstream#README",
"devDependencies": {
"@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"
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/smartfile": "^10.0.33",
"@push.rocks/tapbundle": "^5.0.15"
},
"dependencies": {
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrx": "^2.0.25",
"@types/from2": "^2.3.1",
"@types/through2": "^2.0.36",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/smartrx": "^3.0.7",
"@types/from2": "^2.3.4",
"@types/through2": "^2.0.40",
"from2": "^2.3.0",
"through2": "^4.0.2"
},

5705
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

44
test/test.smartstream.ts Normal file
View File

@ -0,0 +1,44 @@
import { expect, tap } from '@push.rocks/tapbundle';
import { SmartStream } from '../ts/smartstream.classes.smartstream.js'; // Adjust the import to your file structure
import * as smartrx from '@push.rocks/smartrx';
import * as fs from 'fs';
tap.test('should create a SmartStream from a Buffer', async () => {
const bufferData = Buffer.from('This is a test buffer');
const smartStream = SmartStream.fromBuffer(bufferData);
let receivedData = Buffer.alloc(0);
return new Promise<void>((resolve) => {
smartStream.on('data', (chunk: Buffer) => {
receivedData = Buffer.concat([receivedData, chunk]);
});
smartStream.on('end', () => {
expect(receivedData.toString()).toEqual(bufferData.toString());
resolve();
});
});
});
tap.test('should create a SmartStream from an Observable', async () => {
const observableData = 'Observable test data';
const testObservable = smartrx.rxjs.of(Buffer.from(observableData));
const smartStream = SmartStream.fromObservable(testObservable);
let receivedData = Buffer.alloc(0);
return new Promise<void>((resolve) => {
smartStream.on('data', (chunk: Buffer) => {
receivedData = Buffer.concat([receivedData, chunk]);
});
smartStream.on('end', () => {
expect(receivedData.toString()).toEqual(observableData);
resolve();
});
});
});
tap.start();

View File

@ -1,5 +1,5 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartfile from '@pushrocks/smartfile';
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartfile from '@push.rocks/smartfile';
import * as smartstream from '../ts/index.js';

View File

@ -1,13 +1,13 @@
import fs from 'fs';
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartfile from '@push.rocks/smartfile';
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartstream from '../ts/smartstream.classes.streamwrapper.js';
let testSmartstream: smartstream.StreamWrapper;
tap.test('should combine a stream', async () => {
testSmartstream = new smartstream.StreamWrapper([
fs.createReadStream('./test/assets/test.md'),
fs.createWriteStream('./test/assets/testCopy.md'),
smartfile.fsStream.createReadStream('./test/assets/test.md'),
smartfile.fsStream.createWriteStream('./test/assets/testCopy.md'),
]);
await testSmartstream.run();
});

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartstream',
version: '2.0.2',
name: '@push.rocks/smartstream',
version: '2.0.5',
description: 'simplifies access to node streams'
}

View File

@ -1,3 +1,4 @@
export * from './smartstream.classes.smartstream.js';
export * from './smartstream.classes.streamwrapper.js';
export * from './smartstream.classes.streamintake.js';
export * from './smartstream.duplex.js';

View File

@ -0,0 +1,55 @@
import * as plugins from './smartstream.plugins.js';
import { Duplex, type DuplexOptions } from 'stream';
export class SmartStream extends Duplex {
private observableSubscription?: plugins.smartrx.rxjs.Subscription;
constructor(options?: DuplexOptions) {
super(options);
}
_read(size: number) {
// Implement if you need custom behavior, otherwise leave it empty
}
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void) {
// Implement if you need custom behavior
callback();
}
static fromBuffer(buffer: Buffer, options?: DuplexOptions): SmartStream {
const smartStream = new SmartStream(options);
process.nextTick(() => {
smartStream.push(buffer);
smartStream.push(null); // Signal the end of the data
});
return smartStream;
}
static fromObservable(observable: plugins.smartrx.rxjs.Observable<any>, options?: DuplexOptions): SmartStream {
const smartStream = new SmartStream(options);
smartStream.observableSubscription = observable.subscribe({
next: (data) => {
if (!smartStream.push(data)) {
// Pause the observable if the stream buffer is full
smartStream.observableSubscription?.unsubscribe();
smartStream.once('drain', () => {
// Resume the observable when the stream buffer is drained
smartStream.observableSubscription?.unsubscribe();
smartStream.observableSubscription = observable.subscribe(data => {
smartStream.push(data);
});
});
}
},
error: (err) => {
smartStream.emit('error', err);
},
complete: () => {
smartStream.push(null); // Signal the end of the data
}
});
return smartStream;
}
}

View File

@ -4,8 +4,8 @@ import * as stream from 'stream';
export { stream };
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx';
export { smartpromise, smartrx };

View File

@ -3,7 +3,12 @@
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}