fix(core): update
This commit is contained in:
6210
test/assets/readabletext.txt
Normal file
6210
test/assets/readabletext.txt
Normal file
File diff suppressed because it is too large
Load Diff
51
test/assets/writabletext.txt
Normal file
51
test/assets/writabletext.txt
Normal 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
|
68
test/test.streamfunction.ts
Normal file
68
test/test.streamfunction.ts
Normal 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();
|
@ -1,11 +1,11 @@
|
||||
import fs from 'fs';
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartstream from '../ts/index.js';
|
||||
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.Smartstream([
|
||||
testSmartstream = new smartstream.StreamWrapper([
|
||||
fs.createReadStream('./test/assets/test.md'),
|
||||
fs.createWriteStream('./test/assets/testCopy.md'),
|
||||
]);
|
||||
|
Reference in New Issue
Block a user