Skip to main content

Writer contract

Make the output boundary as clear as the input.

A writer object identifies its output format and exposes synchronous, asynchronous, or batched encoding functions. Applications can choose the writer without learning its internal codec.

The writer boundary

Declare the output. Encode the compatible shape.

Writer metadata describes the physical encoding and logical format. The encoder then accepts the category data defined by that format and returns bytes or batches for storage.

Identify

Name, extension, category, and format

Encode

Synchronous or asynchronous output

Stream

Release encoded batches incrementally

Compose

Share category data with compatible writers

To be compatible with @loaders.gl/core functions such as encode, writer objects need to conform to the following specification:

Detailed guide

Writer fields and encoder functions

The sections below define common metadata, synchronous and asynchronous encoders, batched output, and category-data compatibility.

Common fields​

FieldTypePurpose
idstringWriter identifier and option namespace.
namestringHuman-readable writer name.
modulestringOwning loaders.gl module.
versionstringVersion used for runtime assets.
extensionsstring[]Output extensions without leading dots.
optionsobjectDefault writer options.
mimeTypesstring[]Optional output MIME types.
categorystringOptional accepted data category.
encodingstringOptional physical serialization.
formatstringOptional logical format.
workerboolean | stringOptional worker descriptor.

text and binary remain compatibility hints used by encoding helpers. Check the writer reference for accepted input shapes and supported output methods.

Loading an encoder​

A metadata-only Writer can provide preload(), which resolves to a WriterWithEncoder with the same input and options types. Core async encoding APIs call this hook as needed. Batch encoders load on first iteration. For synchronous encoding, pass the bundled encoder or the result of an explicit await writer.preload().

Encoder Function​

FieldTypeDefaultDescription
encodeSyncFunctionnullEncodes synchronously
encodeFunctionnullEncodes asynchronously
encodeInBatches (Experimental)FunctionnullEncodes and releases batches through an async iterator

Note: The format of the input data to the encoders depends on the writer. Category contracts provide shared data shapes, but each writer defines which representations it accepts.