diff --git a/web/lib/avro.ts b/web/lib/avro.ts new file mode 100644 --- /dev/null +++ b/web/lib/avro.ts @@ -0,0 +1,12 @@ +import * as avrojs from "avro-js"; +export namespace avro { + export async function loadType(typeName: string): Promise { + 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 { + const jsMsg = type.fromBuffer(Buffer.from(await b.arrayBuffer())); + return jsMsg; + } +}