Function: createIsoBoxReadableStream()
ts
function createIsoBoxReadableStream(boxes, config?): ReadableStream<Uint8Array<ArrayBuffer>>;Defined in: createIsoBoxReadableStream.ts:25
Creates a ReadableStream of ISO BMFF boxes as Uint8Arrays.
The function reads the global ReadableStream at each call. A polyfill that the caller installs after the import works. The stream writes one box for each read, and writes no box before the first read. An error of any box rejects the read. The stream writes every box into one buffer. The buffer keeps the size of the largest box until the stream ends.
Parameters
boxes
The boxes to stream.
config?
The optional configuration with the writers. With no writers, the function writes only byte arrays, raw boxes, and containers.
Returns
ReadableStream<Uint8Array<ArrayBuffer>>
A new ReadableStream with one chunk for each box.
Throws
Error if ReadableStream is not available in this environment.
Example
ts
const isoFile = await readFile(new URL('./fixtures/captions.mp4', import.meta.url))
const boxes = readIsoBoxes(isoFile, {
readers: {
ftyp: readFtyp,
},
})
const stream = createIsoBoxReadableStream(boxes, {
writers: {
ftyp: writeFtyp,
},
})
const chunks: Uint8Array[] = []
await stream.pipeTo(
new WritableStream({
write(chunk) {
chunks.push(chunk)
},
}),
)