/**
 * Native Stream Implementation - Node.js
 *
 * Uses Node.js native stream module for maximum performance.
 * Provides Readable, Writable, Transform, Duplex, and PassThrough streams.
 */
import { Readable, Writable as NodeWritable, Transform, Duplex, PassThrough } from "stream";
import type { TransformStreamOptions, ReadableStreamOptions, WritableStreamOptions, DuplexStreamOptions, PullStreamOptions, BufferedStreamOptions, ICollector, IDuplex, IEventEmitter, IPassThrough, IReadable, ITransform, IWritable, PipelineStreamLike, ReadableLike, WritableLike } from "./types.js";
import { BufferedStream, BufferChunk, StringChunk } from "./buffered-stream.js";
import { PullStream } from "./pull-stream.js";
/**
 * Extended Writable options that match browser API
 * Supports wrapping an existing Node.js stream
 */
export interface WritableOptions<T = Uint8Array> extends WritableStreamOptions {
    /** Existing Node.js Writable stream to wrap (for API compatibility with browser) */
    stream?: NodeWritable;
    autoDestroy?: boolean;
    emitClose?: boolean;
    defaultEncoding?: BufferEncoding;
    write?: (this: Writable<T>, chunk: T, encoding: BufferEncoding, callback: (error?: Error | null) => void) => void;
    final?: (this: Writable<T>, callback: (error?: Error | null) => void) => void;
}
/**
 * Unified Writable class - wraps Node.js Writable with browser-compatible API
 *
 * Supports the same `{ stream }` option as browser version for wrapping existing streams.
 */
export declare class Writable<T = Uint8Array> extends NodeWritable {
    constructor(options?: WritableOptions<T>);
}
export { Readable, Transform, Duplex, PassThrough };
export { PullStream, BufferedStream, StringChunk, BufferChunk };
/**
 * Normalize a user-provided writable into a Node.js-compatible Writable.
 *
 * This keeps Web/Node branching at the stream-module boundary.
 */
export declare function normalizeWritable<T = Uint8Array>(stream: WritableLike | WritableStream<T> | NodeWritable): WritableLike;
/**
 * Pipeline streams together with proper error handling and cleanup
 * Returns a promise that resolves when the pipeline completes
 */
type PipelineStream = PipelineStreamLike;
type PipelineCallback = (err?: Error | null) => void;
export interface PipelineOptions {
    signal?: AbortSignal;
    end?: boolean;
}
/**
 * Pipeline streams together with proper error handling and cleanup.
 * Node.js compatible with support for options and callbacks.
 */
export declare function pipeline(...args: [...PipelineStream[], PipelineOptions | PipelineCallback] | PipelineStream[]): Promise<void>;
/**
 * Wait for a stream to finish
 */
export interface FinishedOptions {
    readable?: boolean;
    writable?: boolean;
    error?: boolean;
    signal?: AbortSignal;
}
/**
 * Wait for a stream to finish, close, or error.
 * Node.js compatible with support for options and callbacks.
 */
export declare function finished(stream: PipelineStream, optionsOrCallback?: FinishedOptions | PipelineCallback, callback?: PipelineCallback): Promise<void>;
/**
 * Create a readable stream from various sources
 */
export declare function createReadable<_T = Uint8Array>(options?: ReadableStreamOptions & {
    read?: (size: number) => void;
    destroy?: (error: Error | null, callback: (error: Error | null) => void) => void;
}): IReadable<_T>;
/**
 * Create a readable stream from an async iterable
 */
export declare function createReadableFromAsyncIterable<T>(iterable: AsyncIterable<T>, options?: ReadableStreamOptions): IReadable<T>;
/**
 * Create a readable stream from an array
 */
export declare function createReadableFromArray<T>(data: T[], options?: ReadableStreamOptions): IReadable<T>;
/**
 * Create a writable stream
 */
export declare function createWritable<T = Uint8Array>(options?: WritableStreamOptions & {
    write?: (chunk: T, encoding: string, callback: (error?: Error | null) => void) => void;
    final?: (callback: (error?: Error | null) => void) => void;
    destroy?: (error: Error | null, callback: (error: Error | null) => void) => void;
}): IWritable<T>;
/**
 * Create a transform stream from a transform function
 */
export declare function createTransform<TInput = Uint8Array, TOutput = Uint8Array>(transformFn: (chunk: TInput, encoding?: string) => TOutput | Promise<TOutput>, options?: TransformStreamOptions & {
    flush?: () => TOutput | Promise<TOutput> | void;
}): ITransform<TInput, TOutput>;
/**
 * Create a duplex stream
 */
export declare function createDuplex<_TRead = Uint8Array, TWrite = Uint8Array>(options?: DuplexStreamOptions & {
    readable?: unknown;
    writable?: unknown;
    allowHalfOpen?: boolean;
    objectMode?: boolean;
    read?: (this: any, size: number) => void;
    write?: (this: any, chunk: TWrite, encoding: string, callback: (error?: Error | null) => void) => void;
    final?: (this: any, callback: (error?: Error | null) => void) => void;
    destroy?: (this: any, error: Error | null, callback: (error: Error | null) => void) => void;
}): IDuplex<_TRead, TWrite>;
/**
 * Create a passthrough stream
 */
export declare function createPassThrough<_T = any>(options?: TransformStreamOptions): IPassThrough<_T>;
/**
 * A writable stream that collects all chunks
 */
export declare class Collector<T = Uint8Array> extends Writable {
    chunks: T[];
    constructor(options?: WritableStreamOptions);
    /**
     * Get all collected data as a single Uint8Array (for binary mode)
     */
    toUint8Array(): Uint8Array;
    /**
     * Get all collected data as a string
     */
    toString(): string;
}
/**
 * Create a collector stream
 */
export declare function createCollector<T = Uint8Array>(options?: WritableStreamOptions): ICollector<T>;
/**
 * Create a pull stream
 */
export declare function createPullStream(options?: PullStreamOptions): PullStream;
/**
 * Create a buffered stream
 */
export declare function createBufferedStream(options?: BufferedStreamOptions): BufferedStream;
/**
 * Convert a stream to a promise that resolves when finished
 */
export declare function streamToPromise(stream: PipelineStream): Promise<void>;
/**
 * Collect all data from a readable stream into a Uint8Array
 * (Node.js equivalent of browser streamToBuffer)
 */
export declare function streamToBuffer(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>): Promise<Uint8Array>;
/**
 * Collect all data from a readable stream into a Uint8Array
 */
export declare function streamToUint8Array(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>): Promise<Uint8Array>;
/**
 * Collect all data from a readable stream into a string
 */
export declare function streamToString(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>, encoding?: string): Promise<string>;
/**
 * Drain a stream (consume all data without processing)
 */
export declare function drainStream(stream: AsyncIterable<unknown> | ReadableStream<unknown>): Promise<void>;
/**
 * Copy from a readable stream to a writable stream
 */
export declare function copyStream(source: PipelineStreamLike, destination: PipelineStreamLike): Promise<void>;
/**
 * Add abort signal handling to any stream
 */
export declare function addAbortSignal<T extends (ReadableLike | WritableLike) & {
    destroy(error?: Error): any;
}>(signal: AbortSignal, stream: T): T;
/**
 * Create a readable stream from a generator function
 */
export declare function createReadableFromGenerator<T>(generator: () => AsyncGenerator<T, void, unknown>, options?: ReadableStreamOptions): IReadable<T>;
/**
 * Create a readable stream from a Promise
 */
export declare function createReadableFromPromise<T>(promise: Promise<T>, options?: ReadableStreamOptions): IReadable<T>;
/**
 * Compose multiple transform streams into one
 */
export declare function compose<_T = any, _R = any>(...transforms: Array<ITransform<any, any>>): Transform;
/**
 * Wait for multiple streams to finish
 */
export declare function finishedAll(streams: ReadonlyArray<PipelineStreamLike>): Promise<void>;
/**
 * Create a readable stream that emits nothing and immediately ends
 */
export declare function createEmptyReadable<_T = Uint8Array>(options?: ReadableStreamOptions): IReadable<_T>;
/**
 * Create a writable stream that discards all data (like /dev/null)
 */
export declare function createNullWritable<_T = any>(options?: WritableStreamOptions): IWritable<_T>;
/**
 * Promisified version of once for events
 */
export declare function once(emitter: IEventEmitter, event: string, options?: {
    signal?: AbortSignal;
}): Promise<any[]>;
/**
 * Convert a callback-based operation to a promise
 */
export declare function promisify<T>(fn: (callback: (error?: Error | null, result?: T) => void) => void): Promise<T>;
/**
 * Check if an object is a readable stream
 */
export declare function isReadable(obj: unknown): obj is ReadableLike;
/**
 * Check if an object is a writable stream
 */
export declare function isWritable(obj: unknown): obj is WritableLike;
/**
 * Check if an object is a transform stream
 */
export declare function isTransform(obj: unknown): obj is ITransform<any, any>;
/**
 * Check if an object is a duplex stream
 */
export declare function isDuplex(obj: unknown): obj is IDuplex<any, any>;
/**
 * Check if an object is any kind of stream
 */
export declare function isStream(obj: unknown): obj is ReadableLike | WritableLike;
/**
 * Check if a stream has been destroyed
 */
export declare function isDestroyed(stream: {
    destroyed?: boolean;
} | null | undefined): boolean;
/**
 * Check if a readable stream has been disturbed (read from)
 */
export declare function isDisturbed(stream: unknown): boolean;
/**
 * Check if a stream has an error
 */
export declare function isErrored(stream: {
    errored?: unknown;
} | null | undefined): boolean;
/**
 * Get the default high water mark for streams
 */
export declare function getDefaultHighWaterMark(objectMode: boolean): number;
/**
 * Set the default high water mark for streams
 * Note: This is a no-op in this implementation as we use fixed defaults
 */
export declare function setDefaultHighWaterMark(_objectMode: boolean, _value: number): void;
/**
 * Create a pair of connected Duplex streams
 */
export declare function duplexPair<T = Uint8Array>(options?: DuplexStreamOptions): [Duplex, Duplex];
export declare const consumers: {
    arrayBuffer(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>): Promise<ArrayBuffer>;
    blob(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>, options?: BlobPropertyBag): Promise<Blob>;
    buffer(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>): Promise<Uint8Array>;
    json(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>): Promise<any>;
    text(stream: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>, encoding?: string): Promise<string>;
};
export declare const promises: {
    pipeline: typeof pipeline;
    finished: typeof finished;
};
