///
import type { Readable } from "stream";
declare const NOT_READABLE: unique symbol;
declare const READABLE: unique symbol;
declare const ENDED: unique symbol;
declare const ERRORED: unique symbol;
export declare const STATES: {
readonly notReadable: typeof NOT_READABLE;
readonly readable: typeof READABLE;
readonly ended: typeof ENDED;
readonly errored: typeof ERRORED;
};
type States = (typeof STATES)[keyof typeof STATES];
export interface StreamToAsyncIteratorOptions {
/** The size of each read from the stream for each iteration */
size?: number;
}
/**
* Wraps a stream into an object that can be used as an async iterator.
*
* This will keep a stream in a paused state, and will only read from the stream on each
* iteration. A size can be supplied to set an explicit call to `stream.read([size])` in
* the options for each iteration.
*/
export default class StreamToAsyncIterator implements AsyncIterableIterator {
/** The underlying readable stream */
private _stream;
/** Contains stream's error when stream has error'ed out */
private _error;
/** The current state of the iterator (not readable, readable, ended, errored) */
private _state;
private _size;
/** The rejections of promises to call when stream errors out */
private _rejections;
get closed(): boolean;
constructor(stream: Readable, { size }?: StreamToAsyncIteratorOptions);
[Symbol.asyncIterator](): this;
/**
* Returns the next iteration of data. Rejects if the stream errored out.
*/
next(): Promise>;
/**
* Waits until the stream is readable. Rejects if the stream errored out.
* @returns Promise when stream is readable
*/
private _untilReadable;
/**
* Waits until the stream is ended. Rejects if the stream errored out.
* @returns Promise when stream is finished
*/
private _untilEnd;
return(): Promise>;
throw(err?: Error): Promise>;
/**
* Destroy the stream
* @param err An optional error to pass to the stream for an error event
*/
close(err?: Error): void;
private _handleStreamError;
private _handleStreamEnd;
get state(): States;
}
export {};