Class: IOContext
Defined in: src/lib/io-context.ts:74
I/O context for custom input/output operations.
Provides an abstraction layer for all I/O operations in FFmpeg. Enables reading from and writing to various sources including files, network streams, memory buffers, and custom callbacks. Essential for implementing custom protocols or handling non-standard I/O scenarios.
Direct mapping to FFmpeg's AVIOContext.
Example
import { IOContext, FFmpegError } from 'node-av';
import { AVIO_FLAG_READ, AVIO_FLAG_WRITE, AVSEEK_SET } from 'node-av/constants';
// Open file for reading
const io = new IOContext();
const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
FFmpegError.throwIfError(ret, 'open2');
// Read data
const data = await io.read(4096);
if (data instanceof Buffer) {
console.log(`Read ${data.length} bytes`);
}
// Seek to position
const pos = await io.seek(1024n, AVSEEK_SET);
console.log(`Seeked to position ${pos}`);
// Get file size
const fileSize = await io.size();
console.log(`File size: ${fileSize}`);
// Close when done
await io.closep();
// Custom I/O with callbacks
const customIO = new IOContext();
let position = 0n;
const buffer = Buffer.from('Hello World');
customIO.allocContextWithCallbacks(
4096, // Buffer size
0, // Read mode
(size) => {
// Read callback
const end = Number(position) + size;
const chunk = buffer.subarray(Number(position), end);
position = BigInt(end);
return chunk;
},
null, // No write callback for read mode
(offset, whence) => {
// Seek callback
if (whence === AVSEEK_SET) position = offset;
else if (whence === AVSEEK_CUR) position += offset;
else if (whence === AVSEEK_END) position = BigInt(buffer.length) + offset;
return position;
}
);
See
- AVIOContext - FFmpeg Doxygen
- FormatContext For using with demuxing/muxing
Extends
Implements
AsyncDisposable
NativeWrapper
<NativeIOContext
>
Constructors
Constructor
new IOContext():
IOContext
Defined in: src/lib/io-context.ts:75
Returns
IOContext
Overrides
OptionMember<NativeIOContext>.constructor
Properties
native
protected
native:NativeIOContext
Defined in: src/lib/option.ts:999
Inherited from
Accessors
bufferSize
Get Signature
get bufferSize():
number
Defined in: src/lib/io-context.ts:180
Internal buffer size.
Size of the internal buffer used for I/O operations.
Direct mapping to AVIOContext->buffer_size.
Returns
number
direct
Get Signature
get direct():
number
Defined in: src/lib/io-context.ts:154
Direct mode flag.
If set, the I/O context will attempt to avoid buffering.
Direct mapping to AVIOContext->direct.
Returns
number
Set Signature
set direct(
value
):void
Defined in: src/lib/io-context.ts:158
Parameters
value
number
Returns
void
eof
Get Signature
get eof():
boolean
Defined in: src/lib/io-context.ts:104
End of file indicator.
True if end of file has been reached during reading.
Direct mapping to AVIOContext->eof_reached.
Returns
boolean
error
Get Signature
get error():
number
Defined in: src/lib/io-context.ts:115
Error code.
Contains the last error that occurred, or 0 if no error.
Direct mapping to AVIOContext->error.
Returns
number
maxPacketSize
Get Signature
get maxPacketSize():
number
Defined in: src/lib/io-context.ts:139
Maximum packet size.
Used to limit packet sizes in network protocols. 0 means no limit.
Direct mapping to AVIOContext->max_packet_size.
Returns
number
Set Signature
set maxPacketSize(
value
):void
Defined in: src/lib/io-context.ts:143
Parameters
value
number
Returns
void
pos
Get Signature
get pos():
bigint
Defined in: src/lib/io-context.ts:169
Current position.
Current byte position in the stream.
Direct mapping to AVIOContext->pos.
Returns
bigint
seekable
Get Signature
get seekable():
number
Defined in: src/lib/io-context.ts:127
Seekability indicator.
Non-zero if the underlying resource supports seeking. Some protocols like pipes or network streams may not be seekable.
Direct mapping to AVIOContext->seekable.
Returns
number
writeFlag
Get Signature
get writeFlag():
boolean
Defined in: src/lib/io-context.ts:191
Write flag.
True if opened for writing, false for reading.
Direct mapping to AVIOContext->write_flag.
Returns
boolean
Methods
[asyncDispose]()
[asyncDispose]():
Promise
<void
>
Defined in: src/lib/io-context.ts:791
Dispose of the I/O context asynchronously.
Implements the AsyncDisposable interface for automatic cleanup. Closes the context and releases resources.
Returns
Promise
<void
>
Example
{
await using io = new IOContext();
await io.open2('input.mp4');
// Use io...
} // Automatically closed when leaving scope
Implementation of
AsyncDisposable.[asyncDispose]
allocContext()
allocContext(
bufferSize
,writeFlag
):void
Defined in: src/lib/io-context.ts:215
Allocate I/O context with buffer.
Allocates a basic I/O context with an internal buffer. For custom I/O, use allocContextWithCallbacks instead.
Direct mapping to avio_alloc_context() without callbacks.
Parameters
bufferSize
number
Size of internal buffer
writeFlag
number
1 for write, 0 for read
Returns
void
Example
const io = new IOContext();
io.allocContext(4096, 0); // 4KB buffer for reading
See
allocContextWithCallbacks For custom I/O
allocContextWithCallbacks()
allocContextWithCallbacks(
bufferSize
,writeFlag
,readCallback?
,writeCallback?
,seekCallback?
):void
Defined in: src/lib/io-context.ts:274
Allocate I/O context with custom callbacks.
Creates an I/O context with custom read, write, and seek callbacks. Enables implementing custom protocols or data sources.
NOTE: When using JavaScript callbacks, synchronous operations (e.g., readSync, seekSync) cannot be used on this context. This is because JavaScript callbacks require the event loop to be available, which is blocked during synchronous operations. Always use async methods (read, seek) when working with custom callbacks.
Direct mapping to avio_alloc_context() with callbacks.
Parameters
bufferSize
number
Size of internal buffer
writeFlag
1 for write mode, 0 for read mode
0
| 1
readCallback?
Function to read data (null for write-only)
null
| (size
) => null
| number
| Buffer
<ArrayBufferLike
>
writeCallback?
Function to write data (null for read-only)
null
| (buffer
) => number
| void
seekCallback?
Function to seek in stream (optional)
null
| (offset
, whence
) => number
| bigint
Returns
void
Example
import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END, AVSEEK_SIZE } from 'node-av/constants';
const data = Buffer.from('Custom data source');
let position = 0;
io.allocContextWithCallbacks(
4096,
0, // Read mode
(size) => {
// Read callback
if (position >= data.length) return -541; // EOF
const chunk = data.subarray(position, position + size);
position += chunk.length;
return chunk;
},
null,
(offset, whence) => {
// Seek callback
if (whence === AVSEEK_SIZE) return BigInt(data.length);
if (whence === AVSEEK_SET) position = Number(offset);
else if (whence === AVSEEK_CUR) position += Number(offset);
else if (whence === AVSEEK_END) position = data.length + Number(offset);
return BigInt(position);
}
);
See
allocContext For simple allocation
closep()
closep():
Promise
<number
>
Defined in: src/lib/io-context.ts:397
Close I/O context.
Closes the I/O context and releases associated resources. Flushes any buffered data before closing.
Direct mapping to avio_closep().
Returns
Promise
<number
>
0 on success, negative AVERROR on error
Example
const ret = await io.closep();
if (ret < 0) {
console.error('Error closing I/O context');
}
See
open2 To open resources
closepSync()
closepSync():
number
Defined in: src/lib/io-context.ts:422
Close I/O context synchronously. Synchronous version of closep.
Closes the I/O context and frees resources. Sets internal pointer to NULL.
Direct mapping to avio_closep().
Returns
number
0 on success, negative AVERROR on error
Example
const ret = io.closepSync();
if (ret < 0) {
console.error(`Failed to close: ${ret}`);
}
See
closep For async version
flush()
flush():
Promise
<void
>
Defined in: src/lib/io-context.ts:669
Flush buffered data.
Forces any buffered data to be written to the underlying resource.
Direct mapping to avio_flush().
Returns
Promise
<void
>
Example
await io.write(data);
await io.flush(); // Ensure data is written
See
write For writing data
flushSync()
flushSync():
void
Defined in: src/lib/io-context.ts:689
Flush buffered data synchronously. Synchronous version of flush.
Forces any buffered data to be written to the underlying resource.
Direct mapping to avio_flush().
Returns
void
Example
io.writeSync(data);
io.flushSync(); // Ensure data is written
See
flush For async version
freeContext()
freeContext():
void
Defined in: src/lib/io-context.ts:298
Free I/O context.
Releases the I/O context and its resources. The context becomes invalid after calling this.
Direct mapping to avio_context_free().
Returns
void
Example
io.freeContext();
// Context is now invalid
getNative()
getNative():
NativeIOContext
Defined in: src/lib/io-context.ts:772
Internal
Get the underlying native IOContext object.
Returns
The native IOContext binding object
Implementation of
getOption()
Get an option value from this object.
Uses the AVOption API to retrieve options.
Direct mapping to av_opt_get* functions.
Param
Option name
Param
Option type (defaults to AV_OPT_TYPE_STRING)
Param
Search flags (default: AV_OPT_SEARCH_CHILDREN)
Example
import { AV_OPT_TYPE_STRING, AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_PIXEL_FMT, AV_OPT_TYPE_INT64 } from 'node-av/constants';
// String options (default)
const preset = obj.getOption('preset');
const codec = obj.getOption('codec', AV_OPT_TYPE_STRING);
// Typed options
const framerate = obj.getOption('framerate', AV_OPT_TYPE_RATIONAL); // Returns {num, den}
const pixFmt = obj.getOption('pix_fmt', AV_OPT_TYPE_PIXEL_FMT); // Returns AVPixelFormat
const bitrate = obj.getOption('bitrate', AV_OPT_TYPE_INT64); // Returns bigint
Call Signature
getOption(
name
,type?
,searchFlags?
):null
|string
Defined in: src/lib/option.ts:1217
Parameters
name
string
type?
searchFlags?
Returns
null
| string
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|string
Defined in: src/lib/option.ts:1218
Parameters
name
string
type
searchFlags?
Returns
null
| string
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|number
Defined in: src/lib/option.ts:1221
Parameters
name
string
type
searchFlags?
Returns
null
| number
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|bigint
Defined in: src/lib/option.ts:1222
Parameters
name
string
type
searchFlags?
Returns
null
| bigint
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|number
Defined in: src/lib/option.ts:1223
Parameters
name
string
type
searchFlags?
Returns
null
| number
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|bigint
Defined in: src/lib/option.ts:1224
Parameters
name
string
type
searchFlags?
Returns
null
| bigint
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|number
Defined in: src/lib/option.ts:1225
Parameters
name
string
type
searchFlags?
Returns
null
| number
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|boolean
Defined in: src/lib/option.ts:1226
Parameters
name
string
type
searchFlags?
Returns
null
| boolean
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|number
Defined in: src/lib/option.ts:1227
Parameters
name
string
type
searchFlags?
Returns
null
| number
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|number
Defined in: src/lib/option.ts:1228
Parameters
name
string
type
searchFlags?
Returns
null
| number
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|number
Defined in: src/lib/option.ts:1231
Parameters
name
string
type
searchFlags?
Returns
null
| number
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|number
Defined in: src/lib/option.ts:1232
Parameters
name
string
type
searchFlags?
Returns
null
| number
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|IRational
Defined in: src/lib/option.ts:1235
Parameters
name
string
type
searchFlags?
Returns
null
| IRational
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|IRational
Defined in: src/lib/option.ts:1236
Parameters
name
string
type
searchFlags?
Returns
null
| IRational
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|AVPixelFormat
Defined in: src/lib/option.ts:1237
Parameters
name
string
type
searchFlags?
Returns
null
| AVPixelFormat
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|AVSampleFormat
Defined in: src/lib/option.ts:1238
Parameters
name
string
type
searchFlags?
Returns
null
| AVSampleFormat
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
| {height
:number
;width
:number
; }
Defined in: src/lib/option.ts:1239
Parameters
name
string
type
searchFlags?
Returns
null
| { height
: number
; width
: number
; }
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|ChannelLayout
Defined in: src/lib/option.ts:1240
Parameters
name
string
type
searchFlags?
Returns
null
| ChannelLayout
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|Dictionary
Defined in: src/lib/option.ts:1241
Parameters
name
string
type
searchFlags?
Returns
null
| Dictionary
Inherited from
Call Signature
getOption(
name
,type
,searchFlags?
):null
|string
Defined in: src/lib/option.ts:1242
Parameters
name
string
type
searchFlags?
Returns
null
| string
Inherited from
listOptions()
listOptions():
OptionInfo
[]
Defined in: src/lib/option.ts:1358
List all available options for this object.
Uses the AVOption API to enumerate all options. Useful for discovering available settings and their types.
Direct mapping to av_opt_next() iteration.
Returns
Array of option information objects
Example
const options = obj.listOptions();
for (const opt of options) {
console.log(`${opt.name}: ${opt.help}`);
console.log(` Type: ${opt.type}, Default: ${opt.defaultValue}`);
console.log(` Range: ${opt.min} - ${opt.max}`);
}
See
OptionInfo For option metadata structure
Inherited from
open2()
open2(
url
,flags
):Promise
<number
>
Defined in: src/lib/io-context.ts:335
Open resource for I/O.
Opens a URL or file for reading or writing. Automatically selects the appropriate protocol handler.
Direct mapping to avio_open2().
Parameters
url
string
URL or file path to open
flags
AVIOFlag
= AVIO_FLAG_READ
Open flags (AVIO_FLAG_READ, AVIO_FLAG_WRITE, etc.)
Returns
Promise
<number
>
0 on success, negative AVERROR on error:
- AVERROR_ENOENT: File not found
- AVERROR_EACCES: Permission denied
- AVERROR_ENOMEM: Memory allocation failure
Example
import { FFmpegError } from 'node-av';
import { AVIO_FLAG_READ, AVIO_FLAG_WRITE } from 'node-av/constants';
// Open for reading
const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
FFmpegError.throwIfError(ret, 'open2');
// Open for writing
const ret2 = await io.open2('output.mp4', AVIO_FLAG_WRITE);
FFmpegError.throwIfError(ret2, 'open2');
See
closep To close after use
open2Sync()
open2Sync(
url
,flags
):number
Defined in: src/lib/io-context.ts:373
Open resource for I/O synchronously. Synchronous version of open2.
Opens a URL or file for reading or writing. Automatically selects the appropriate protocol handler.
Direct mapping to avio_open2().
Parameters
url
string
URL or file path to open
flags
AVIOFlag
= AVIO_FLAG_READ
Open flags (AVIO_FLAG_READ, AVIO_FLAG_WRITE, etc.)
Returns
number
0 on success, negative AVERROR on error:
- AVERROR_ENOENT: File not found
- AVERROR_EACCES: Permission denied
- AVERROR_ENOMEM: Memory allocation failure
Example
import { FFmpegError } from 'node-av';
import { AVIO_FLAG_READ, AVIO_FLAG_WRITE } from 'node-av/constants';
// Open for reading
const ret = io.open2Sync('input.mp4', AVIO_FLAG_READ);
FFmpegError.throwIfError(ret, 'open2');
// Open for writing
const ret2 = io.open2Sync('output.mp4', AVIO_FLAG_WRITE);
FFmpegError.throwIfError(ret2, 'open2');
See
open2 For async version
read()
read(
size
):Promise
<number
|Buffer
<ArrayBufferLike
>>
Defined in: src/lib/io-context.ts:451
Read data from I/O context.
Reads up to the specified number of bytes from the stream.
Direct mapping to avio_read().
Parameters
size
number
Maximum number of bytes to read
Returns
Promise
<number
| Buffer
<ArrayBufferLike
>>
Buffer with data, or error code if negative:
- AVERROR_EOF: End of file reached
- AVERROR_EIO: I/O error
Example
const data = await io.read(4096);
if (data instanceof Buffer) {
console.log(`Read ${data.length} bytes`);
} else {
console.error(`Read error: ${data}`);
}
See
write For writing data
readSync()
readSync(
size
):number
|Buffer
<ArrayBufferLike
>
Defined in: src/lib/io-context.ts:479
Read data from I/O context synchronously. Synchronous version of read.
Reads up to the specified number of bytes from the stream.
Direct mapping to avio_read().
Parameters
size
number
Number of bytes to read
Returns
number
| Buffer
<ArrayBufferLike
>
Buffer with data, or negative AVERROR on error
Example
const result = io.readSync(4096);
if (Buffer.isBuffer(result)) {
console.log(`Read ${result.length} bytes`);
} else {
console.log(`Read error: ${result}`);
}
See
read For async version
seek()
seek(
offset
,whence
):Promise
<bigint
>
Defined in: src/lib/io-context.ts:560
Seek to position in stream.
Changes the current position in the stream. Not all streams support seeking.
Direct mapping to avio_seek().
Parameters
offset
bigint
Byte offset to seek to
whence
Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END)
Returns
Promise
<bigint
>
New position, or negative AVERROR on error:
- AVERROR_EINVAL: Invalid arguments
- AVERROR_ENOSYS: Seeking not supported
Example
import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av/constants';
// Seek to absolute position
const pos1 = await io.seek(1024n, AVSEEK_SET);
// Seek relative to current position
const pos2 = await io.seek(512n, AVSEEK_CUR);
// Seek relative to end
const pos3 = await io.seek(-1024n, AVSEEK_END);
See
seekSync()
seekSync(
offset
,whence
):bigint
Defined in: src/lib/io-context.ts:597
Seek to position in stream synchronously. Synchronous version of seek.
Changes the current position in the stream. Not all streams support seeking.
Direct mapping to avio_seek().
Parameters
offset
bigint
Byte offset to seek to
whence
Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END)
Returns
bigint
New position, or negative AVERROR on error:
- AVERROR_EINVAL: Invalid arguments
- AVERROR_ENOSYS: Seeking not supported
Example
import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av/constants';
// Seek to absolute position
const pos1 = io.seekSync(1024n, AVSEEK_SET);
// Seek relative to current position
const pos2 = io.seekSync(512n, AVSEEK_CUR);
// Seek relative to end
const pos3 = io.seekSync(-1024n, AVSEEK_END);
See
seek For async version
setOption()
Set an option on this object.
Uses the AVOption API to set options. Available options depend on the specific object type.
Direct mapping to av_opt_set* functions.
Param
Option name
Param
Option value
Param
Option type (defaults to AV_OPT_TYPE_STRING)
Param
Search flags (default: AV_OPT_SEARCH_CHILDREN)
Example
import { FFmpegError } from 'node-av';
import { AV_OPT_TYPE_STRING, AV_OPT_TYPE_INT64, AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_PIXEL_FMT } from 'node-av/constants';
// String options (default)
let ret = obj.setOption('preset', 'fast');
FFmpegError.throwIfError(ret, 'set preset');
ret = obj.setOption('codec', 'h264', AV_OPT_TYPE_STRING);
FFmpegError.throwIfError(ret, 'set codec');
// Integer options
ret = obj.setOption('bitrate', 2000000, AV_OPT_TYPE_INT64);
FFmpegError.throwIfError(ret, 'set bitrate');
ret = obj.setOption('threads', 4, AV_OPT_TYPE_INT);
FFmpegError.throwIfError(ret, 'set threads');
// Complex types with proper types
ret = obj.setOption('framerate', {num: 30, den: 1}, AV_OPT_TYPE_RATIONAL);
FFmpegError.throwIfError(ret, 'set framerate');
ret = obj.setOption('pix_fmt', AV_PIX_FMT_YUV420P, AV_OPT_TYPE_PIXEL_FMT);
FFmpegError.throwIfError(ret, 'set pixel format');
Call Signature
setOption(
name
,value
,type?
,searchFlags?
):number
Defined in: src/lib/option.ts:1006
Parameters
name
string
value
string
type?
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1007
Parameters
name
string
value
string
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1010
Parameters
name
string
value
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1011
Parameters
name
string
value
bigint
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1012
Parameters
name
string
value
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1013
Parameters
name
string
value
bigint
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1014
Parameters
name
string
value
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1015
Parameters
name
string
value
boolean
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1016
Parameters
name
string
value
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1017
Parameters
name
string
value
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1020
Parameters
name
string
value
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1021
Parameters
name
string
value
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1024
Parameters
name
string
value
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1025
Parameters
name
string
value
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1026
Parameters
name
string
value
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1027
Parameters
name
string
value
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1028
Parameters
name
string
value
height
number
width
number
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1029
Parameters
name
string
value
number
| bigint
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1030
Parameters
name
string
value
Buffer
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1031
Parameters
name
string
value
number
[]
type
searchFlags?
Returns
number
Inherited from
Call Signature
setOption(
name
,value
,type
,searchFlags?
):number
Defined in: src/lib/option.ts:1032
Parameters
name
string
value
type
searchFlags?
Returns
number
Inherited from
size()
size():
Promise
<bigint
>
Defined in: src/lib/io-context.ts:622
Get stream size.
Returns the total size of the stream in bytes. Not all streams have a known size.
Direct mapping to avio_size().
Returns
Promise
<bigint
>
Size in bytes, or negative AVERROR if unknown:
- AVERROR_ENOSYS: Size not available
Example
const size = await io.size();
if (size >= 0n) {
console.log(`Stream size: ${size} bytes`);
} else {
console.log('Stream size unknown');
}
sizeSync()
sizeSync():
bigint
Defined in: src/lib/io-context.ts:650
Get stream size synchronously. Synchronous version of size.
Returns the total size of the stream in bytes. Not all streams have a known size.
Direct mapping to avio_size().
Returns
bigint
Size in bytes, or negative AVERROR if unknown:
- AVERROR_ENOSYS: Size not available
Example
const size = io.sizeSync();
if (size >= 0n) {
console.log(`Stream size: ${size} bytes`);
} else {
console.log('Stream size unknown');
}
See
size For async version
skip()
skip(
offset
):Promise
<bigint
>
Defined in: src/lib/io-context.ts:714
Skip bytes in stream.
Advances the position by the specified offset. More efficient than reading and discarding data.
Direct mapping to avio_skip().
Parameters
offset
bigint
Number of bytes to skip
Returns
Promise
<bigint
>
New position after skipping
Example
// Skip 1024 bytes forward
const newPos = await io.skip(1024n);
console.log(`New position: ${newPos}`);
See
seek For absolute positioning
skipSync()
skipSync(
offset
):bigint
Defined in: src/lib/io-context.ts:740
Skip bytes in stream synchronously. Synchronous version of skip.
Advances the position by the specified offset. More efficient than reading and discarding data.
Direct mapping to avio_skip().
Parameters
offset
bigint
Number of bytes to skip
Returns
bigint
New position after skipping
Example
// Skip 1024 bytes forward
const newPos = io.skipSync(1024n);
console.log(`New position: ${newPos}`);
See
skip For async version
tell()
tell():
bigint
Defined in: src/lib/io-context.ts:761
Get current position.
Returns the current byte position in the stream.
Direct mapping to avio_tell().
Returns
bigint
Current position in bytes
Example
const position = io.tell();
console.log(`Current position: ${position}`);
See
seek To change position
write()
write(
buffer
):Promise
<void
>
Defined in: src/lib/io-context.ts:501
Write data to I/O context.
Writes buffer data to the stream.
Direct mapping to avio_write().
Parameters
buffer
Buffer
Data to write
Returns
Promise
<void
>
Example
const data = Buffer.from('Hello World');
await io.write(data);
See
writeSync()
writeSync(
buffer
):void
Defined in: src/lib/io-context.ts:523
Write data to I/O context synchronously. Synchronous version of write.
Writes buffer data to the stream.
Direct mapping to avio_write().
Parameters
buffer
Buffer
Data to write
Returns
void
Example
const data = Buffer.from('Hello, World!');
io.writeSync(data);
See
write For async version
fromNative()
static
fromNative(native
):IOContext
Defined in: src/lib/io-context.ts:91
Internal
Find input format by short name.
Creates an IOContext instance from a native binding object. Used internally for wrapping native I/O contexts.
Parameters
native
Native IOContext binding object
Returns
IOContext
Wrapped IOContext instance