Skip to content

node-av / api / IOStream

Class: IOStream

Defined in: src/api/io-stream.ts:47

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

typescript
import { IOStream, MediaInput } from 'node-av/api';

// From buffer
const buffer = await fs.readFile('video.mp4');
const ioContext = IOStream.create(buffer);
const input = await MediaInput.open(buffer);
typescript
// Custom I/O callbacks
const callbacks = {
  read: async (size: number) => {
    // Read from custom source
    return Buffer.alloc(size);
  },
  seek: async (offset: bigint, whence: number) => {
    // Seek in custom source
    return offset;
  }
};

const ioContext = IOStream.create(callbacks, {
  bufferSize: 4096
});

See

Constructors

Constructor

new IOStream(): IOStream

Returns

IOStream

Methods

create()

Call Signature

static create(buffer, options?): IOContext

Defined in: src/api/io-stream.ts:68

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?

MediaInputOptions

I/O configuration options

Returns

IOContext

Configured I/O context

Example
typescript
const buffer = await fs.readFile('video.mp4');
const ioContext = IOStream.create(buffer, {
  bufferSize: 8192
});

Call Signature

static create(callbacks, options?): IOContext

Defined in: src/api/io-stream.ts:95

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

IOInputCallbacks

I/O callbacks for read and seek operations

options?

MediaInputOptions

I/O configuration options

Returns

IOContext

Configured I/O context

Throws

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);
  }
});