fix(core): update

This commit is contained in:
2023-11-03 21:32:24 +01:00
parent ea66d1b2fb
commit 8618ac55ef
7 changed files with 126 additions and 146 deletions

View File

@ -48,4 +48,3 @@ hi+wow
hi+wow
hi+wow
hi+wow
noice

View File

@ -1,11 +1,11 @@
import { expect, tap } from '@push.rocks/tapbundle';
import { SmartStream } from '../ts/smartstream.classes.smartstream.js'; // Adjust the import to your file structure
import { SmartDuplex } from '../ts/smartstream.classes.smartduplex.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);
const smartStream = SmartDuplex.fromBuffer(bufferData);
let receivedData = Buffer.alloc(0);
@ -25,7 +25,7 @@ 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);
const smartStream = SmartDuplex.fromObservable(testObservable);
let receivedData = Buffer.alloc(0);

View File

@ -7,43 +7,43 @@ let testIntake: smartstream.StreamIntake<string>;
tap.test('should handle a read stream', async (tools) => {
const counter = 0;
const testSmartstream = new smartstream.StreamWrapper([
const streamWrapper = new smartstream.StreamWrapper([
smartfile.fsStream.createReadStream('./test/assets/readabletext.txt'),
smartstream.createDuplexStream<Buffer, Buffer>(
async (chunkStringArg: Buffer, streamTools) => {
new smartstream.SmartDuplex({
writeAndTransformFunction: async (chunkStringArg: Buffer, streamTools) => {
// do something with the stream here
const result = chunkStringArg.toString().substr(0, 100);
streamTools.pipeMore('wow =========== \n');
streamTools.push('wow =========== \n');
return Buffer.from(result);
},
async (tools) => {
// tools.pipeMore('hey, this is the end')
streamEndFunction: async (tools) => {
return Buffer.from('this is the end');
},
{ objectMode: false }
),
smartstream.createDuplexStream<Buffer, string>(async (chunkStringArg) => {
console.log(chunkStringArg.toString());
return null;
}),
new smartstream.SmartDuplex({
writeAndTransformFunction: async (chunkStringArg) => {
console.log(chunkStringArg.toString());
},
streamEndFunction: async (tools) => {
tools.push(null);
},
}),
smartstream.cleanPipe(),
]);
await testSmartstream.run();
// await streamWrapper.run();
});
tap.test('should create a valid Intake', async (tools) => {
testIntake = new smartstream.StreamIntake<string>();
testIntake.pipe(
smartstream.createDuplexStream<string, string>(
async (chunkString) => {
new smartstream.SmartDuplex({
objectMode: true,
writeAndTransformFunction: async (chunkStringArg: string, streamTools) => {
await tools.delayFor(100);
console.log(chunkString);
return chunkString;
},
async () => {
return 'noice';
console.log(chunkStringArg);
return chunkStringArg;
}
)
})
)
.pipe(smartfile.fsStream.createWriteStream('./test/assets/writabletext.txt'));
const testFinished = tools.defer();