UNPKG

@loaders.gl/bson

Version:

Framework-independent loader for JSON and streaming JSON formats

19 lines (15 loc) 534 B
// loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import type {SerializeOptions} from 'bson'; import * as BSON from 'bson'; import {ensureArrayBuffer} from '@loaders.gl/loader-utils'; export type EncodeBSONOptions = SerializeOptions; export function encodeBSONSync( value: Record<string, unknown>, options?: EncodeBSONOptions ): ArrayBuffer { const uint8Array = BSON.serialize(value); // TODO - make sure the uint8array occupies the entire buffer. return ensureArrayBuffer(uint8Array); }