UNPKG

958 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.readableFrom = exports.readableCreate = void 0;
4const stream_1 = require("stream");
5/**
6 * Convenience function to create a Readable that can be pushed into (similar to RxJS Subject).
7 * Push `null` to it to complete (similar to RxJS `.complete()`).
8 *
9 * Difference from Readable.from() is that this readable is not "finished" yet and allows pushing more to it.
10 */
11function readableCreate(items = [], opt) {
12 const readable = new stream_1.Readable({
13 objectMode: true,
14 ...opt,
15 read() { },
16 });
17 for (const item of items) {
18 readable.push(item);
19 }
20 return readable;
21}
22exports.readableCreate = readableCreate;
23/**
24 * Convenience type-safe wrapper around Readable.from() that infers the Type of input.
25 */
26function readableFrom(items, opt) {
27 return stream_1.Readable.from(items, opt);
28}
29exports.readableFrom = readableFrom;