UNPKG

1.94 kBTypeScriptView Raw
1/// <reference types="node" />
2import { BufferLike } from '../interfaces';
3import { Readable, ReadableOptions } from 'stream';
4declare type AsyncSourceIterator<TSource> = AsyncIterator<TSource, any, number | ArrayBufferView | undefined | null>;
5export declare class AsyncIterableReadable<T> extends Readable {
6 private _pulling;
7 private _objectMode;
8 private _iterator;
9 constructor(source: AsyncIterable<T>, options?: ReadableOptions);
10 _read(size: number): void;
11 _destroy(err: Error | null, cb: (err: Error | null) => void): void;
12 _pull(it: AsyncSourceIterator<T>, size: number): Promise<boolean>;
13}
14/**
15 * Converts an existing async-iterable to a Node.js stream.
16 * @param source The async-iterable to convert to a Node.js stream.
17 * @param options The optional Readable options for the Node.js stream.
18 */
19export declare function toNodeStream<TSource>(source: AsyncIterable<TSource>): AsyncIterableReadable<TSource>;
20export declare function toNodeStream<TSource>(source: AsyncIterable<TSource>, options: ReadableOptions & {
21 objectMode: true;
22}): AsyncIterableReadable<TSource>;
23export declare function toNodeStream<TSource extends BufferLike>(source: AsyncIterable<TSource>, options: ReadableOptions & {
24 objectMode: false;
25}): AsyncIterableReadable<TSource>;
26/**
27 * @ignore
28 */
29export declare function toNodeStreamProto<TSource>(this: AsyncIterable<TSource>): AsyncIterableReadable<TSource>;
30export declare function toNodeStreamProto<TSource>(this: AsyncIterable<TSource>, options: ReadableOptions & {
31 objectMode: true;
32}): AsyncIterableReadable<TSource>;
33export declare function toNodeStreamProto<TSource extends BufferLike>(this: AsyncIterable<TSource>, options: ReadableOptions & {
34 objectMode: false;
35}): AsyncIterableReadable<TSource>;
36declare module '../asynciterable/asynciterablex' {
37 interface AsyncIterableX<T> {
38 toNodeStream: typeof toNodeStreamProto;
39 }
40}
41export {};