2023-11-01 13:16:58 +00:00
|
|
|
import { expect, tap } from '@push.rocks/tapbundle';
|
2023-11-03 20:32:24 +00:00
|
|
|
import { SmartDuplex } from '../ts/smartstream.classes.smartduplex.js'; // Adjust the import to your file structure
|
2023-11-01 13:16:58 +00:00
|
|
|
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');
|
2023-11-03 20:32:24 +00:00
|
|
|
const smartStream = SmartDuplex.fromBuffer(bufferData);
|
2023-11-01 13:16:58 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2023-11-03 20:32:24 +00:00
|
|
|
const smartStream = SmartDuplex.fromObservable(testObservable);
|
2023-11-01 13:16:58 +00:00
|
|
|
|
|
|
|
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();
|