Skip to content
Class

AppendOnlyStreamTarget

This target writes to a WritableStream<Uint8Array>, meaning all writes are necessarily append-only and involve no seeking. Great for streaming data to a source that can only accept sequential data, like an HTTP server processing an incoming upload.

Note that using this target requires that the underlying format write data sequentially. Not all formats do this, and this target will throw for the formats that don't. Check the guide for more.

Extends: Target

Constructor

ts
constructor(
	writable: WritableStream<Uint8Array>,
): AppendOnlyStreamTarget;

Events

onwrite

ts
onwrite: ((start: number, end: number) => unknown) | null;

Called each time data is written to the target. Will be called with the byte range into which data was written.

Use this callback to track the size of the output file as it grows. But be warned, this function is chatty and gets called extremely often.

Methods

slice()

ts
slice(
	offset: number,
): RangedTarget;

Returns a new RangedTarget that writes data to this target using the given offset.

Useful for writing a file into a section of a larger file.

Released under the Mozilla Public License 2.0.