Compare commits

...

12 Commits

Author SHA1 Message Date
2c904cc1ec 2.0.8 2023-11-02 00:30:16 +01:00
d1561ad1b7 fix(core): update 2023-11-02 00:30:15 +01:00
0ae3fee987 2.0.7 2023-11-01 14:18:35 +01:00
047c2bd402 fix(core): update 2023-11-01 14:18:34 +01:00
9ed3de718f 2.0.6 2023-11-01 14:17:39 +01:00
14530f393c fix(core): update 2023-11-01 14:17:39 +01:00
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
14 changed files with 5857 additions and 11080 deletions

View File

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

View File

@ -7,10 +7,10 @@
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartstream", "gitrepo": "smartstream",
"description": "simplifies access to node streams", "description": "simplifies access to node streams",
"npmPackagename": "@pushrocks/smartstream", "npmPackagename": "@push.rocks/smartstream",
"license": "MIT" "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", "name": "@push.rocks/smartstream",
"version": "2.0.2", "version": "2.0.8",
"private": false, "private": false,
"description": "simplifies access to node streams", "description": "simplifies access to node streams",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -21,18 +21,17 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartstream#README", "homepage": "https://gitlab.com/pushrocks/smartstream#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.63", "@git.zone/tsbuild": "^2.1.66",
"@gitzone/tstest": "^1.0.71", "@git.zone/tsrun": "^1.2.44",
"@pushrocks/smartfile": "^10.0.0", "@git.zone/tstest": "^1.0.77",
"@pushrocks/tapbundle": "^5.0.3", "@push.rocks/smartfile": "^10.0.33",
"tslint": "^6.1.3", "@push.rocks/tapbundle": "^5.0.15"
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.1.7", "@push.rocks/smartpromise": "^4.0.3",
"@pushrocks/smartrx": "^2.0.25", "@push.rocks/smartrx": "^3.0.7",
"@types/from2": "^2.3.1", "@types/from2": "^2.3.4",
"@types/through2": "^2.0.36", "@types/through2": "^2.0.40",
"from2": "^2.3.0", "from2": "^2.3.0",
"through2": "^4.0.2" "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 { expect, tap } from '@push.rocks/tapbundle';
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@push.rocks/smartfile';
import * as smartstream from '../ts/index.js'; import * as smartstream from '../ts/index.js';

View File

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

View File

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

View File

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

View File

@ -0,0 +1,19 @@
import * as plugins from './smartstream.plugins.js';
export class PassThrough extends plugins.stream.Duplex {
constructor(options?: plugins.stream.DuplexOptions) {
super(options);
}
_read(size: number): void {
// No-op: Data written will be automatically available for reading.
}
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
if (this.push(chunk, encoding)) {
callback();
} else {
this.once('drain', callback);
}
}
}

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 }; export { stream };
// pushrocks scope // pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx'; import * as smartrx from '@push.rocks/smartrx';
export { smartpromise, smartrx }; export { smartpromise, smartrx };

View File

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