function auHeader
auHeader(): Coder<AuHeader>

Creates a coder for a Sun/NeXT .au file header.

The annotation field's length is derived from dataOffset (dataOffset - 24), so a header with no annotation needs dataOffset = 24 and an empty annotation.

Nothing is validated or computed on encode — magic, dataOffset and dataSize are written exactly as given. Set dataOffset to 24 + annotation.length yourself.

Examples

Header carrying an annotation

import { assertEquals } from "@std/assert";
import { auHeader, AU_ENCODING, AU_HEADER_SIZE, AU_MAGIC } from "@binstruct/au";

const annotation = new TextEncoder().encode("take 1\0\0");
const coder = auHeader();
const header = {
  magic: AU_MAGIC,
  dataOffset: AU_HEADER_SIZE + annotation.length,
  dataSize: 8000,
  encoding: AU_ENCODING.MULAW_8,
  sampleRate: 8000,
  channels: 1,
  annotation,
};

const buffer = new Uint8Array(64);
const written = coder.encode(header, buffer);
const [decoded, read] = coder.decode(buffer.subarray(0, written));

assertEquals(written, AU_HEADER_SIZE + annotation.length);
assertEquals(read, written);
assertEquals(decoded.annotation, annotation);
assertEquals(decoded.dataOffset, 32);

Unknown data size

import { assertEquals } from "@std/assert";
import { auHeader, AU_DATA_SIZE_UNKNOWN } from "@binstruct/au";

// deno-fmt-ignore
const wire = new Uint8Array([
  0x2e, 0x73, 0x6e, 0x64,
  0x00, 0x00, 0x00, 0x18,
  0xff, 0xff, 0xff, 0xff,
  0x00, 0x00, 0x00, 0x01,
  0x00, 0x00, 0x1f, 0x40,
  0x00, 0x00, 0x00, 0x01,
]);

const [decoded, read] = auHeader().decode(wire);

assertEquals(read, 24);
assertEquals(decoded.dataSize, AU_DATA_SIZE_UNKNOWN);
assertEquals(decoded.sampleRate, 8000);
assertEquals(decoded.annotation.length, 0);

Return Type

Coder<AuHeader>

A coder for AuHeader values.

Usage

import { auHeader } from ".";