Portable output
Encode the data you already have.
Convert application and category data at the edge of the pipeline, then let a format-specific writer own validation, compression, and output bytes.
Core API
Using writers
Turn tables, geometry, images, and other application data back into portable files with the same explicit module boundaries used for loading.
Portable output
One application shape. Many destinations.
Writers keep encoding at the edge of the pipeline. Prepare a documented category shape, choose the destination format, and let that writer own its physical layout and compression.
Application data
Writer boundary
validate · encode · compress
Portable files
The application chooses the data shape; the writer chooses the bytes.
The writer path
Encode the application shape you already have.
Writers sit at the far edge of a pipeline. Convert into the format’s documented input shape, choose the output container, and keep format-specific encoding behind one explicit module.
Prepare
Use a category shape or format-specific writer input
Encode
Call encode() or encodeSync() with one writer
Compress
Pass codec and container options where supported
Save
Write a buffer, stream, file, or application response
Writers allow applications to encode data into many of the formats supported by loaders.gl. Import a writer from its format entry point to load its encoder on the first async write. Use the format’s /bundled entry point for synchronous encoding and direct encoder methods.
For a detailed specification of the writer object format see the API reference.
Detailed guide
Writer inputs and output behavior
The guide below covers writer selection, category-compatible input data, asynchronous encoding, options, and format-specific boundaries.
Usage
As an example, to Draco-compress a mesh using the DracoWriter:
import {DracoWriter} from '@loaders.gl/scene/draco';
import {encode} from '@loaders.gl/core';
const mesh = {
attributes: {
POSITION: {...}
}
};
const data = await encode(mesh, DracoWriter);
Input Data
Writers accept the same format of data that is produced by the corresponding loaders. This format is documented either in each loader or usually as part of the documentation for that loader category.
Mesh category writers can accept either plain Mesh objects or Mesh Arrow tables. Plain Mesh data is normalized through the Mesh Arrow table conversion path before encoding.
If applications have data in a different format, they will need to first transform the data to the format expected by the writer.