/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Buffer } from 'buffer';
import { Socket } from 'net';
import { Readable, Writable, Duplex } from 'stream';
import { Emitter, Event, Disposable } from 'vscode-jsonrpc';
import { CancellationToken } from './util/cancellation';
/**
 * Stream interface used by the SSH library. Implementations of this interface
 * allow the SSH protocol to communicate over different transport mechanisms.
 */
export interface Stream extends Disposable {
    /**
     * Reads bytes from the stream.
     * @param count Maximum number of bytes to read.
     * @param cancellation Optional cancellation token.
     * @returns Buffer containing the bytes read, or null if the end of the
     * (cleanly closed) stream was reached. The buffer length is less than or
     * equal to the requested count.
     * @throws If there was an error reading from the stream.
     */
    read(count: number, cancellation?: CancellationToken): Promise<Buffer | null>;
    /**
     * Writes bytes to the stream.
     * @param data Buffer containing bytes to write.
     * @param cancellation Optional cancellation token.
     * @throws If there was an error writing to the stream.
     */
    write(data: Buffer, cancellation?: CancellationToken): Promise<void>;
    /**
     * Closes the stream.
     * @param error Error that caused the stream closure, if any.
     */
    close(error?: Error, cancellation?: CancellationToken): Promise<void>;
    /**
     * Event raised when the stream was closed.
     * @param error Error that caused the stream closure, if any.
     */
    readonly closed: Event<{
        error?: Error;
    }>;
    /**
     * Gets a value indicating whether the stream is disposed.
     */
    readonly isDisposed: boolean;
}
/**
 * Base class for stream adapters.
 */
export declare abstract class BaseStream implements Stream {
    private readonly incomingData;
    private readonly pendingReads;
    private error;
    protected disposed: boolean;
    protected onData(data: Buffer): void;
    protected onEnd(): void;
    protected onError(error: Error): void;
    read(count: number, cancellation?: CancellationToken): Promise<Buffer | null>;
    abstract write(data: Buffer, cancellation?: CancellationToken): Promise<void>;
    abstract close(error?: Error, cancellation?: CancellationToken): Promise<void>;
    protected readonly closedEmitter: Emitter<{
        error?: Error | undefined;
    }>;
    readonly closed: Event<{
        error?: Error;
    }>;
    dispose(): void;
    protected fireOnClose(error?: Error): void;
    get isDisposed(): boolean;
}
/**
 * Stream adapter for a Node.js Socket, Duplex stream, or Readable/Writable stream pair.
 */
export declare class NodeStream extends BaseStream {
    private readonly readStream;
    private readonly writeStream;
    constructor(duplexStream: Duplex | Socket);
    constructor(readStream: Readable, writeStream: Writable);
    write(data: Buffer, cancellation?: CancellationToken): Promise<void>;
    close(error?: Error, cancellation?: CancellationToken): Promise<void>;
    dispose(): void;
}
interface WebSocketLike {
    readonly protocol?: string;
    onmessage: ((e: {
        data: ArrayBuffer;
    }) => void) | null;
    onclose: ((e: {
        code: number;
        reason: string;
        wasClean: boolean;
    }) => void) | null;
    send(data: ArrayBuffer): void;
    close(code?: number, reason?: string): void;
}
/**
 * Stream adapter for a browser websocket.
 */
export declare class WebSocketStream extends BaseStream {
    private readonly websocket;
    constructor(websocket: WebSocket | WebSocketLike);
    get protocol(): string | undefined;
    write(data: Buffer, cancellation?: CancellationToken): Promise<void>;
    close(error?: Error, cancellation?: CancellationToken): Promise<void>;
    dispose(): void;
}
export {};
//# sourceMappingURL=streams.d.ts.map