Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
9ed3de718f | |||
14530f393c | |||
15a226d30d | |||
16c5c89662 | |||
851a96c014 | |||
4ea42cb9fb | |||
41eed6423d | |||
0e067004a4 |
@ -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
|
||||||
|
@ -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
11052
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstream",
|
"name": "@push.rocks/smartstream",
|
||||||
"version": "2.0.2",
|
"version": "2.0.6",
|
||||||
"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
5705
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
44
test/test.smartstream.ts
Normal file
44
test/test.smartstream.ts
Normal 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();
|
@ -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';
|
||||||
|
|
||||||
|
@ -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();
|
||||||
});
|
});
|
||||||
|
@ -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.6',
|
||||||
description: 'simplifies access to node streams'
|
description: 'simplifies access to node streams'
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
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';
|
55
ts/smartstream.classes.smartstream.ts
Normal file
55
ts/smartstream.classes.smartstream.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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 };
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user