import { Readable } from 'node:stream';
import { IOContext } from '../lib/index.js';
import type { Writable } from 'node:stream';
import type { AVSeekWhence } from '../constants/index.js';
import type { DemuxerOptions } from './demuxer.js';
import type { MuxerOptions } from './muxer.js';
/**
 * Custom I/O callbacks for implementing custom input sources.
 *
 */
export interface IOInputCallbacks {
    /**
     * Read callback - called when FFmpeg needs to read data.
     *
     * Can be synchronous or async (return a Promise).
     *
     * @param size - Number of bytes to read
     *
     * @returns Buffer with data, null for EOF, negative error code, or Promise resolving to same
     */
    read: (size: number) => Buffer | null | number | Promise<Buffer | null | number>;
    /**
     * Seek callback - called when FFmpeg needs to seek in the stream.
     *
     * Can be synchronous or async (return a Promise).
     *
     * @param offset - Offset to seek to
     *
     * @param whence - Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END, or AVSEEK_SIZE)
     *
     * @returns New position, negative error code, or Promise resolving to same
     */
    seek?: (offset: bigint, whence: AVSeekWhence) => bigint | number | Promise<bigint | number>;
}
/**
 * Custom I/O callbacks for implementing custom output targets.
 *
 */
export interface IOOutputCallbacks {
    /**
     * Write callback - called when FFmpeg needs to write data.
     *
     * Can be synchronous or async (return a Promise).
     * The buffer may be reused by FFmpeg after the callback completes,
     * so copy it if you need to keep the data.
     *
     * @param buffer - Buffer containing data to write
     *
     * @returns Number of bytes written, void (assumes all bytes written), or Promise resolving to same
     */
    write: (buffer: Buffer) => number | void | Promise<number | void>;
    /**
     * Seek callback - called when FFmpeg needs to seek in the output.
     *
     * Can be synchronous or async (return a Promise).
     *
     * @param offset - Offset to seek to
     *
     * @param whence - Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END)
     *
     * @returns New position, negative error code, or Promise resolving to same
     */
    seek?: (offset: bigint, whence: AVSeekWhence) => bigint | number | Promise<bigint | number>;
    /**
     * Read callback - some formats may need to read back data.
     *
     * Can be synchronous or async (return a Promise).
     *
     * @param size - Number of bytes to read
     *
     * @returns Buffer with data, null for EOF, negative error code, or Promise resolving to same
     */
    read?: (size: number) => Buffer | null | number | Promise<Buffer | null | number>;
}
/**
 * Factory for creating custom I/O contexts.
 *
 * Provides simplified creation of I/O contexts from buffers or custom callbacks.
 * Handles buffer management and seek operations for in-memory media.
 * Bridges the gap between high-level media operations and custom I/O sources.
 * Essential for processing media from non-file sources like network streams or memory.
 *
 * @example
 * ```typescript
 * import { IOStream, Demuxer } from 'node-av/api';
 *
 * // From buffer
 * const buffer = await fs.readFile('video.mp4');
 * const ioContext = IOStream.create(buffer);
 * const input = await Demuxer.open(buffer);
 * ```
 *
 * @example
 * ```typescript
 * // Custom I/O callbacks
 * const callbacks = {
 *   read: async (size: number) => {
 *     // Read from custom source
 *     return Buffer.alloc(size);
 *   },
 *   seek: async (offset: bigint, whence: AVSeekWhence) => {
 *     // Seek in custom source
 *     return offset;
 *   }
 * };
 *
 * const ioContext = IOStream.create(callbacks, {
 *   bufferSize: 4096
 * });
 * ```
 *
 * @see {@link IOContext} For low-level I/O operations
 * @see {@link Demuxer} For using I/O contexts
 * @see {@link IOInputCallbacks} For callback interface
 */
export declare class IOStream {
    /**
     * Create I/O context from buffer.
     *
     * Creates an I/O context from an in-memory buffer for reading media data.
     * Automatically handles seek operations and position tracking.
     *
     * @param buffer - Buffer containing media data
     *
     * @param options - I/O configuration options
     *
     * @returns Configured I/O context
     *
     * @example
     * ```typescript
     * const buffer = await fs.readFile('video.mp4');
     * const ioContext = IOStream.create(buffer, {
     *   bufferSize: 8192
     * });
     * ```
     */
    static create(buffer: Buffer, options?: DemuxerOptions): IOContext;
    /**
     * Create I/O context from callbacks.
     *
     * Creates an I/O context using custom read and seek callbacks.
     * Useful for streaming from non-file sources like network or custom storage.
     *
     * @param callbacks - I/O callbacks for read and seek operations
     *
     * @param options - I/O configuration options
     *
     * @returns Configured I/O context
     *
     * @throws {Error} If callbacks missing required read function
     *
     * @example
     * ```typescript
     * const ioContext = IOStream.create({
     *   read: async (size) => {
     *     return await customSource.read(size);
     *   },
     *   seek: async (offset, whence) => {
     *     return await customSource.seek(offset, whence);
     *   }
     * });
     * ```
     */
    static create(callbacks: IOInputCallbacks, options?: DemuxerOptions): IOContext;
    /**
     * Create I/O context from a Node.js Readable stream.
     *
     * Creates an I/O context that reads from a Readable stream.
     * Seeking is not supported for streams.
     *
     * @param stream - Node.js Readable stream
     *
     * @param options - I/O configuration options
     *
     * @returns Configured I/O context
     *
     * @example
     * ```typescript
     * const readable = fs.createReadStream('video.mkv');
     * const ioContext = IOStream.create(readable, { format: 'matroska' });
     * ```
     */
    static create(stream: Readable, options?: DemuxerOptions): IOContext;
    /**
     * Create I/O context for writing to a Node.js Writable stream.
     *
     * Creates a write-mode I/O context from a Writable stream with
     * backpressure support and automatic buffer copying.
     * Seeking is not supported for streams.
     *
     * @param stream - Node.js Writable stream
     *
     * @param options - Output configuration options
     *
     * @returns Configured I/O context
     *
     * @example
     * ```typescript
     * const writable = fs.createWriteStream('output.mkv');
     * const ioContext = IOStream.createOutput(writable, { format: 'matroska' });
     * ```
     */
    static createOutput(stream: Writable, options?: MuxerOptions): IOContext;
    /**
     * Create I/O context from custom output callbacks.
     *
     * Creates a write-mode I/O context using custom write, optional seek,
     * and optional read callbacks.
     *
     * @param callbacks - I/O callbacks for write, seek, and read operations
     *
     * @param options - Output configuration options
     *
     * @returns Configured I/O context
     *
     * @throws {Error} If callbacks missing required write function
     *
     * @example
     * ```typescript
     * const chunks: Buffer[] = [];
     * const ioContext = IOStream.createOutput({
     *   write: (buffer) => {
     *     chunks.push(Buffer.from(buffer));
     *     return buffer.length;
     *   }
     * }, { format: 'matroska' });
     * ```
     */
    static createOutput(callbacks: IOOutputCallbacks, options?: MuxerOptions): IOContext;
    /**
     * Create I/O context from buffer.
     *
     * Sets up read and seek callbacks for in-memory buffer.
     * Manages position tracking and EOF handling.
     *
     * @param buffer - Source buffer
     *
     * @param bufferSize - Internal buffer size
     *
     * @returns Configured I/O context
     *
     * @internal
     */
    private static createFromBuffer;
    /**
     * Create I/O context from a Node.js Readable stream.
     *
     * Sets up async read callbacks that buffer data from the stream.
     * Seeking is not supported for streams.
     *
     * @param stream - Node.js Readable stream
     *
     * @param bufferSize - Internal buffer size
     *
     * @returns Configured I/O context
     *
     * @internal
     */
    private static createFromReadable;
    /**
     * Create I/O context for writing to a Node.js Writable stream.
     *
     * Sets up async write callbacks with backpressure support.
     * The buffer is copied before writing since FFmpeg reuses its internal buffer.
     *
     * @param stream - Node.js Writable stream
     *
     * @param bufferSize - Internal buffer size
     *
     * @param maxPacketSize - Maximum packet size
     *
     * @returns Configured I/O context
     *
     * @internal
     */
    private static createForWritable;
    /**
     * Create I/O context from custom input callbacks.
     *
     * Sets up custom I/O with user-provided read and optional seek callbacks.
     *
     * @param callbacks - User I/O callbacks
     *
     * @param bufferSize - Internal buffer size
     *
     * @returns Configured I/O context
     *
     * @internal
     */
    private static createFromInputCallbacks;
    /**
     * Create I/O context from custom output callbacks.
     *
     * Sets up custom I/O with user-provided write, optional seek, and optional read callbacks.
     *
     * @param callbacks - User I/O callbacks
     *
     * @param bufferSize - Internal buffer size
     *
     * @param maxPacketSize - Maximum packet size
     *
     * @returns Configured I/O context
     *
     * @internal
     */
    private static createFromOutputCallbacks;
}
