import { Duplex } from 'node:stream';
declare const ByteStreamInfo: unique symbol;
interface IByteStreamInfo {
    receivers: Map<number, SrpcByteStream>;
    senders: Map<number, SrpcByteStream>;
    nextId: number;
    step: number;
    pendingReceivers?: Map<number, IPendingReceiver>;
    pendingReceiverBytes: number;
}
interface IPendingReceiver {
    chunks: Buffer[];
    bytes: number;
    finished: boolean;
    destroyedError?: Error;
    timeout?: ReturnType<typeof setTimeout>;
}
export interface IByteStream {
    [ByteStreamInfo]?: IByteStreamInfo;
    write(streamId: number, data: unknown): boolean | void | Promise<boolean | void>;
    finish(streamId: number): void;
    destroy(streamId: number, err?: unknown): void;
    attachDisconnectHandler(handler: () => void): void;
    detachDisconnectHandler(handler: () => void): void;
    getBufferedAmount(): number;
    parentStreamId: string;
}
export interface IByteStreamable {
    byteStream: IByteStream;
}
export declare class SrpcByteStream extends Duplex {
    private readonly _id;
    private readonly parent;
    private readonly isSender;
    private cleaned;
    private remotelyDestroyed;
    private remoteFinished;
    private localFinished;
    get id(): number;
    constructor(stream: IByteStreamable, id?: number);
    static init(stream: IByteStreamable, options: {
        startId: number;
        step: number;
    }): void;
    static createReceiver(stream: IByteStreamable, id: number): SrpcByteStream;
    static createSender(stream: IByteStreamable): SrpcByteStream;
    static writeReceiver(stream: IByteStreamable, id: number, data: unknown): void;
    static finishReceiver(stream: IByteStreamable, id: number): void;
    static destroySubstream(stream: IByteStreamable, id: number, err?: string): void;
    _read(): void;
    _write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
    _final(callback: (error?: Error | null) => void): void;
    _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
    private flushPendingReceiver;
    private readonly handleDisconnect;
    private cleanup;
    private static ensureInfo;
}
export {};
//# sourceMappingURL=SrpcByteStream.d.ts.map