view web/lib/avro.ts @ 2450:a4052905ca7d default tip

notes about how rdfdb syncs, or should sync
author drewp@bigasterisk.com
date Mon, 03 Jun 2024 23:01:54 -0700
parents ef3cde3e81e8
children
line wrap: on
line source

import * as avrojs from "avro-js";
export namespace avro {
  export async function loadType(typeName: string): Promise<avrojs.types.Type> {
    const schemaSource = await (await fetch(`/avro/${typeName}.avsc`)).json();
    return await avrojs.parse(schemaSource);
  }
  
  export async function parseBlob(type: avrojs.types.Type, b: Blob): Promise<avrojs.types.Record> {
    const jsMsg = type.fromBuffer(Buffer.from(await b.arrayBuffer()));
    return jsMsg;
  }
}