Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Vanilagy/mediabunny/llms.txt
Use this file to discover all available pages before exploring further.
Source
The base class representing a resource from which bytes can be read.Methods
Returns the total size of the file in bytes. This function is memoized, meaning only the first call will retrieve the size.Throws an error if the source is unsized.
Returns the total size of the file in bytes, or null if the source is unsized. This function is memoized.
Called each time data is retrieved from the source. Will be called with the retrieved range (end exclusive).
BufferSource
A source backed by an ArrayBuffer or ArrayBufferView, with the entire file held in memory.Constructor
The buffer to use as the source data.
Example
BlobSource
A source backed by aBlob. Since a File is also a Blob, this is the source to use when reading files off the disk in the browser.
Constructor
The Blob to use as the source.
Optional configuration.
Options
The maximum number of bytes the cache is allowed to hold in memory. Defaults to 8 MiB.
Example
UrlSource
A source backed by a URL. This is useful for reading data from the network. Requests will be made using an optimized reading and prefetching pattern to minimize request count and latency.Constructor
The URL to fetch data from.
Optional configuration.
Options
The
RequestInit used by the Fetch API. Can be used to further control the requests, such as setting custom headers.All fields will work except for signal and headers.Range; these will be overridden by Mediabunny.options.getRetryDelay
(previousAttempts: number, error: unknown, url: string | URL | Request) => number | null
A function that returns the delay (in seconds) before retrying a failed request. If the function returns
null, no more retries will be made.By default, uses an exponential backoff algorithm that never gives up unless a CORS error is suspected.The maximum number of bytes the cache is allowed to hold in memory. Defaults to 64 MiB.
The maximum number of parallel requests to use for fetching. Defaults to 2.
A WHATWG-compatible fetch function. You can use this field to polyfill the
fetch function, add missing features, or use a custom implementation.Example
FilePathSource
A source backed by a path to a file. Intended for server-side usage in Node, Bun, or Deno.Make sure to call
.dispose() on the corresponding Input when done to explicitly free the internal file handle acquired by this source.Constructor
The path to the file to read.
Optional configuration.
Options
The maximum number of bytes the cache is allowed to hold in memory. Defaults to 8 MiB.
Example
StreamSource
A general-purpose, callback-driven source that can get its data from anywhere.Constructor
Configuration for the stream source.
Options
Called when the size of the entire file is requested. Must return or resolve to the size in bytes. This function is guaranteed to be called before
read.options.read
(start: number, end: number) => MaybePromise<Uint8Array | ReadableStream<Uint8Array>>
required
Called when data is requested. Must return or resolve to the bytes from the specified byte range, or a stream that yields these bytes.
Called when the
Input driven by this source is disposed.The maximum number of bytes the cache is allowed to hold in memory. Defaults to 8 MiB.
Specifies the prefetch profile that the reader should use with this source.
'none': No prefetching; only the data needed in the moment is requested.'fileSystem': File system-optimized prefetching with small bidirectional prefetching aligned with page boundaries.'network': Network-optimized prefetching for high-latency environments; minimizes read calls and aggressively prefetches data when sequential access patterns are detected.
Example
ReadableStreamSource
A source backed by aReadableStream of Uint8Array, representing an append-only byte stream of unknown length. This is useful for incrementally streaming in input files that are still being constructed, like the output chunks of MediaRecorder.
This source is unsized, meaning calls to
.getSize() will throw. You should only use this source with sequential access patterns. This source does not work well with random access patterns unless you increase its max cache size.Constructor
The readable stream to use as the source.
Optional configuration.
Options
The maximum number of bytes the cache is allowed to hold in memory. Defaults to 16 MiB.