import { Uint8ArrayList } from 'uint8arraylist'; import type { MessageStream, Stream, AbortOptions } from '@libp2p/interface'; import type { Duplex, Transform, Sink } from 'it-stream-types'; export declare class UnwrappedError extends Error { static name: string; name: string; } /** * The reported length of the next data message was not a positive integer */ export declare class InvalidMessageLengthError extends Error { name: string; code: string; } /** * The reported length of the next data message was larger than the configured * max allowable value */ export declare class InvalidDataLengthError extends Error { name: string; code: string; } /** * The varint used to specify the length of the next data message contained more * bytes than the configured max allowable value */ export declare class InvalidDataLengthLengthError extends Error { name: string; code: string; } export interface ByteStreamOpts { /** * Incoming bytes are buffered until read, this setting limits how many bytes * will be buffered. * * @default 4_194_304 */ maxBufferSize?: number; } export interface ReadBytesOptions extends AbortOptions { /** * If specified, read this number of bytes from the stream */ bytes: number; } export interface ByteStream { /** * Read bytes from the stream. * * If a required number of bytes is passed as an option, this will wait for * the underlying stream to supply that number of bytes, throwing an * `UnexpectedEOFError` if the stream closes before this happens. * * If no required number of bytes is passed, this will return `null` if the * underlying stream closes before supplying any bytes. */ read(options: ReadBytesOptions): Promise; read(options?: AbortOptions): Promise; /** * Write the passed bytes to the stream */ write(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Promise; /** * After calling this method the stream can no longer be used. Any unread data * will be emitted as a message event during the microtask queue of the * current event loop tick. */ unwrap(): S; } export declare function byteStream(stream: T, opts?: ByteStreamOpts): ByteStream; export interface LengthPrefixedStream { /** * Read the next length-prefixed number of bytes from the stream */ read(options?: AbortOptions): Promise; /** * Write the passed bytes to the stream prefixed by their length */ write(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Promise; /** * Write passed list of bytes, prefix by their individual lengths to the stream as a single write */ writeV(input: Array, options?: AbortOptions): Promise; /** * Returns the underlying stream */ unwrap(): S; } export interface LengthPrefixedStreamOpts extends ByteStreamOpts { lengthEncoder(value: number): Uint8ArrayList | Uint8Array; lengthDecoder(data: Uint8ArrayList): number; maxLengthLength: number; maxDataLength: number; } export declare function lpStream(stream: T, opts?: Partial): LengthPrefixedStream; /** * A protobuf decoder - takes a byte array and returns an object */ export interface ProtobufDecoder { (data: Uint8Array | Uint8ArrayList): T; } /** * A protobuf encoder - takes an object and returns a byte array */ export interface ProtobufEncoder { (data: T): Uint8Array; } /** * Convenience methods for working with protobuf streams */ export interface ProtobufStream { /** * Read the next length-prefixed byte array from the stream and decode it as the passed protobuf format */ read(proto: { decode: ProtobufDecoder; }, options?: AbortOptions): Promise; /** * Encode the passed object as a protobuf message and write it's length-prefixed bytes to the stream */ write(data: T, proto: { encode: ProtobufEncoder; }, options?: AbortOptions): Promise; /** * Encode the passed objects as protobuf messages and write their length-prefixed bytes to the stream as a single write */ writeV(input: T[], proto: { encode: ProtobufEncoder; }, options?: AbortOptions): Promise; /** * Returns an object with read/write methods for operating on one specific type of protobuf message */ pb(proto: { encode: ProtobufEncoder; decode: ProtobufDecoder; }): ProtobufMessageStream; /** * Returns the underlying stream */ unwrap(): S; } /** * A message reader/writer that only uses one type of message */ export interface ProtobufMessageStream { /** * Read a message from the stream */ read(options?: AbortOptions): Promise; /** * Write a message to the stream */ write(d: T, options?: AbortOptions): Promise; /** * Write several messages to the stream */ writeV(d: T[], options?: AbortOptions): Promise; /** * Unwrap the underlying protobuf stream */ unwrap(): ProtobufStream; } export interface ProtobufStreamOpts extends LengthPrefixedStreamOpts { } export declare function pbStream(stream: T, opts?: Partial): ProtobufStream; export declare function echo(stream: MessageStream, options?: AbortOptions): Promise; export type PipeInput = Iterable | AsyncIterable | Stream; export declare function messageStreamToDuplex(stream: Stream): Duplex, Iterable | AsyncIterable, Promise>; interface SourceFn { (): A; } type PipeSource = Iterable | AsyncIterable | SourceFn | Duplex | MessageStream; type PipeTransform = Transform | Duplex | MessageStream; type PipeSink = Sink | Duplex | MessageStream; type PipeOutput = A extends Sink ? ReturnType : A extends Duplex ? ReturnType : A extends MessageStream ? Promise : never; type SingleItemPipeOutput = A extends Iterable ? A : A extends AsyncIterable ? A : A extends SourceFn ? ReturnType : A extends Duplex ? A['source'] : PipeOutput; type PipeFnInput = A extends Iterable ? A : A extends AsyncIterable ? A : A extends SourceFn ? ReturnType : A extends Transform ? ReturnType : A extends Duplex ? A['source'] : never; export declare function pipe(source: A): SingleItemPipeOutput; export declare function pipe>>(source: A, sink: B): PipeOutput; export declare function pipe>, C extends PipeSink>>(source: A, transform1: B, sink: C): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeSink>>(source: A, transform1: B, transform2: C, sink: D): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, sink: E): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeTransform>, F extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, transform4: E, sink: F): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeTransform>, F extends PipeTransform>, G extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, transform4: E, transform5: F, sink: G): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeTransform>, F extends PipeTransform>, G extends PipeTransform>, H extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, transform4: E, transform5: F, transform6: G, sink: H): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeTransform>, F extends PipeTransform>, G extends PipeTransform>, H extends PipeTransform>, I extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, transform4: E, transform5: F, transform6: G, transform7: H, sink: I): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeTransform>, F extends PipeTransform>, G extends PipeTransform>, H extends PipeTransform>, I extends PipeTransform>, J extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, transform4: E, transform5: F, transform6: G, transform7: H, transform8: I, sink: J): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeTransform>, F extends PipeTransform>, G extends PipeTransform>, H extends PipeTransform>, I extends PipeTransform>, J extends PipeTransform>, K extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, transform4: E, transform5: F, transform6: G, transform7: H, transform8: I, transform9: J, sink: K): PipeOutput; export declare function pipe>, C extends PipeTransform>, D extends PipeTransform>, E extends PipeTransform>, F extends PipeTransform>, G extends PipeTransform>, H extends PipeTransform>, I extends PipeTransform>, J extends PipeTransform>, K extends PipeTransform>, L extends PipeSink>>(source: A, transform1: B, transform2: C, transform3: D, transform4: E, transform5: F, transform6: G, transform7: H, transform8: I, transform9: J, transform10: K, sink: L): PipeOutput; export {}; //# sourceMappingURL=stream-utils.d.ts.map