NodeIO

I/O service for Node.js.

The most common use of the I/O service is to read/write a Document with a given path. Methods are also available for converting in-memory representations of raw glTF files, both binary (Uint8Array) and JSON (JSONDocument).

Usage:

import { NodeIO } from '@gltf-transform/core';

const io = new NodeIO();

// Read.
let document;
document = await io.read('model.glb'); // → Document
document = await io.readBinary(glb);   // Uint8Array → Document

// Write.
await io.write('model.glb', document);      // → void
const glb = await io.writeBinary(document); // Document → Uint8Array

By default, NodeIO can only read/write paths on disk. To enable network requests, provide a Fetch API implementation (global fetch() is stable in Node.js v21+, or node-fetch may be installed) and enable setAllowNetwork. Network requests may optionally be configured with RequestInit parameters.

const io = new NodeIO(fetch, {headers: {...}}).setAllowNetwork(true);

const document = await io.read('https://example.com/path/to/model.glb');

Hierarchy

Constructor

  • constructor(_fetch?: unknown, _fetchConfig?: RequestInit): NodeIO
  • Constructs a new NodeIO service. Instances are reusable. By default, only NodeIO can only read/write paths on disk. To enable HTTP requests, provide a Fetch API implementation and enable setAllowNetwork.

Properties

Methods

  • setAllowNetwork(allow: boolean): NodeIO
  • binaryToJSON(glb: Uint8Array): Promise<JSONDocument>
  • init(): Promise<void>
  • read(uri: string): Promise<Document>
  • readAsJSON(uri: string): Promise<JSONDocument>
  • readBinary(glb: Uint8Array): Promise<Document>
  • registerDependencies(dependencies: { [key: string]: unknown }): PlatformIO
  • registerExtensions(extensions: (typeof Extension)[]): PlatformIO
  • write(uri: string, doc: Document): Promise<void>
  • writeBinary(doc: Document): Promise<Uint8Array>
  • writeJSON(doc: Document, _options?: PublicWriterOptions): Promise<JSONDocument>
Function symbol, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.