Skip to main content
If you are not using a framework, or just want to use the standard browser API, here is the pattern.

The Wrapper

import { ZonReader } from '@zon-lib/zon';

async function fetchZon(url) {
  const response = await fetch(url);
  if (!response.ok) throw new Error('Network response was not ok');
  
  const arrayBuffer = await response.arrayBuffer();
  return new ZonReader(new Uint8Array(arrayBuffer));
}

Usage

document.getElementById('load-btn').addEventListener('click', async () => {
  const reader = await fetchZon('/data/level1.zon');
  
  const root = reader.rootOffset;
  const levelName = reader.readString(root);
  
  console.log('Loaded Level:', levelName);
});