Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
c8465b82be | |||
b593e3a32c | |||
a490f521ab | |||
59027782dc | |||
8c7dd7970c | |||
22d18dc21f | |||
1cb6f727af | |||
824c44d165 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@push.rocks/smartstream",
|
||||
"version": "3.0.40",
|
||||
"version": "3.0.44",
|
||||
"private": false,
|
||||
"description": "A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.",
|
||||
"type": "module",
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartstream',
|
||||
version: '3.0.40',
|
||||
version: '3.0.44',
|
||||
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
import { stream } from './smartstream.plugins.js';
|
||||
export {
|
||||
stream,
|
||||
}
|
||||
|
||||
export * from './smartstream.classes.smartduplex.js';
|
||||
export * from './smartstream.classes.streamwrapper.js';
|
||||
export * from './smartstream.classes.streamintake.js';
|
||||
|
@ -158,7 +158,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
||||
callback();
|
||||
}
|
||||
|
||||
public getWebStreams(): { readable: ReadableStream, writable: WritableStream } {
|
||||
public async getWebStreams(): Promise<{ readable: ReadableStream, writable: WritableStream }> {
|
||||
const duplex = this;
|
||||
const readable = new ReadableStream({
|
||||
start(controller) {
|
||||
|
@ -1,6 +1,45 @@
|
||||
import * as plugins from './smartstream.plugins.js';
|
||||
|
||||
export class StreamIntake<T> extends plugins.stream.Readable {
|
||||
// STATIC
|
||||
public static async fromStream<U>(inputStream: plugins.stream.Readable | ReadableStream, options?: plugins.stream.ReadableOptions): Promise<StreamIntake<U>> {
|
||||
const intakeStream = new StreamIntake<U>(options);
|
||||
|
||||
if (inputStream instanceof plugins.stream.Readable) {
|
||||
inputStream.on('data', (chunk: U) => {
|
||||
intakeStream.pushData(chunk);
|
||||
});
|
||||
|
||||
inputStream.on('end', () => {
|
||||
intakeStream.signalEnd();
|
||||
});
|
||||
|
||||
inputStream.on('error', (err: Error) => {
|
||||
intakeStream.destroy(err);
|
||||
});
|
||||
} else {
|
||||
const reader = (inputStream as ReadableStream).getReader();
|
||||
|
||||
const readChunk = () => {
|
||||
reader.read().then(({ done, value }) => {
|
||||
if (done) {
|
||||
intakeStream.signalEnd();
|
||||
} else {
|
||||
intakeStream.pushData(value);
|
||||
readChunk();
|
||||
}
|
||||
}).catch((err) => {
|
||||
intakeStream.destroy(err);
|
||||
});
|
||||
};
|
||||
|
||||
readChunk();
|
||||
}
|
||||
|
||||
return intakeStream;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
private signalEndBoolean = false;
|
||||
private chunkStore: T[] = [];
|
||||
public pushNextObservable = new plugins.smartrx.ObservableIntake<any>();
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartstream',
|
||||
version: '3.0.40',
|
||||
version: '3.0.44',
|
||||
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
||||
}
|
||||
|
Reference in New Issue
Block a user