1 | import { Readable, ReadableOptions } from 'stream'
|
2 | import { ReadableTyped } from '../stream.model'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export function readableCreate<T>(
|
11 | items: Iterable<T> = [],
|
12 | opt?: ReadableOptions,
|
13 | ): ReadableTyped<T> {
|
14 | const readable = new Readable({
|
15 | objectMode: true,
|
16 | ...opt,
|
17 | read() {},
|
18 | })
|
19 | for (const item of items) {
|
20 | readable.push(item)
|
21 | }
|
22 | return readable
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export function readableFrom<T>(
|
29 | items: Iterable<T> | AsyncIterable<T>,
|
30 | opt?: ReadableOptions,
|
31 | ): ReadableTyped<T> {
|
32 | return Readable.from(items, opt)
|
33 | }
|