Class: IOStream
Defined in: src/api/io-stream.ts:127
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.
Examples
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);// 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
- IOContext For low-level I/O operations
- Demuxer For using I/O contexts
- IOInputCallbacks For callback interface
Constructors
Constructor
new IOStream():
IOStream
Returns
IOStream
Methods
create()
Call Signature
staticcreate(buffer,options?):IOContext
Defined in: src/api/io-stream.ts:148
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.
Parameters
buffer
Buffer
Buffer containing media data
options?
I/O configuration options
Returns
Configured I/O context
Example
const buffer = await fs.readFile('video.mp4');
const ioContext = IOStream.create(buffer, {
bufferSize: 8192
});Call Signature
staticcreate(callbacks,options?):IOContext
Defined in: src/api/io-stream.ts:175
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.
Parameters
callbacks
I/O callbacks for read and seek operations
options?
I/O configuration options
Returns
Configured I/O context
Throws
If callbacks missing required read function
Example
const ioContext = IOStream.create({
read: async (size) => {
return await customSource.read(size);
},
seek: async (offset, whence) => {
return await customSource.seek(offset, whence);
}
});Call Signature
staticcreate(stream,options?):IOContext
Defined in: src/api/io-stream.ts:194
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.
Parameters
stream
Readable
Node.js Readable stream
options?
I/O configuration options
Returns
Configured I/O context
Example
const readable = fs.createReadStream('video.mkv');
const ioContext = IOStream.create(readable, { format: 'matroska' });createOutput()
Call Signature
staticcreateOutput(stream,options?):IOContext
Defined in: src/api/io-stream.ts:235
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.
Parameters
stream
Writable
Node.js Writable stream
options?
Output configuration options
Returns
Configured I/O context
Example
const writable = fs.createWriteStream('output.mkv');
const ioContext = IOStream.createOutput(writable, { format: 'matroska' });Call Signature
staticcreateOutput(callbacks,options?):IOContext
Defined in: src/api/io-stream.ts:261
Create I/O context from custom output callbacks.
Creates a write-mode I/O context using custom write, optional seek, and optional read callbacks.
Parameters
callbacks
I/O callbacks for write, seek, and read operations
options?
Output configuration options
Returns
Configured I/O context
Throws
If callbacks missing required write function
Example
const chunks: Buffer[] = [];
const ioContext = IOStream.createOutput({
write: (buffer) => {
chunks.push(Buffer.from(buffer));
return buffer.length;
}
}, { format: 'matroska' });