function ustarHeader
ustarHeader(): Coder<UstarHeader>

Creates a coder for a single 512-byte POSIX ustar header block.

Covers header layout only, matching UstarHeader: the six numeric fields (mode, uid, gid, size, mtime, checksum) round-trip through number, the remaining text fields round-trip through trimmed string, and padding is exposed as the raw trailing 12 bytes. Nothing is validated or computed on encode — checksum in particular is written exactly as given.

Examples

Decode a known header and re-encode it byte-for-byte

import { assertEquals } from "@std/assert";
import { TAR_BLOCK_SIZE, TAR_TYPEFLAG, ustarHeader } from "@binstruct/tar";

const coder = ustarHeader();

const buffer = new Uint8Array(TAR_BLOCK_SIZE);
const written = coder.encode({
  name: "dir/file.txt",
  mode: 0o100644,
  uid: 0,
  gid: 0,
  size: 11,
  mtime: 1_700_000_000,
  checksum: 0,
  typeflag: TAR_TYPEFLAG.regularFile,
  linkname: "",
  magic: "ustar",
  version: "00",
  uname: "root",
  gname: "root",
  devmajor: "",
  devminor: "",
  prefix: "",
  padding: new Uint8Array(12),
}, buffer);

const [decoded, read] = coder.decode(buffer);

assertEquals(written, TAR_BLOCK_SIZE);
assertEquals(read, TAR_BLOCK_SIZE);
assertEquals(decoded.name, "dir/file.txt");
assertEquals(decoded.mode, 0o100644);
assertEquals(decoded.size, 11);
assertEquals(decoded.typeflag, TAR_TYPEFLAG.regularFile);

Return Type

Coder<UstarHeader>

A coder for UstarHeader values.

Usage

import { ustarHeader } from ".";