Skip to content

Format Specification

This document describes the ZIGX archive format (version 1).

Overview

ZIGX archives consist of four main sections:

  1. Header (128 bytes) - Fixed-size metadata
  2. Metadata (variable) - Key-value pairs
  3. Checksums (variable) - File integrity data
  4. Compressed Payload - File contents

Header Format

The header is exactly 128 bytes:

OffsetSizeFieldDescription
04MagicZIGX (0x5A494758)
42VersionFormat version (0x0001)
64FlagsFeature flags
104File CountNumber of files
148Original SizeUncompressed size
228Payload LengthCompressed size
308Meta LengthMetadata section size
388Checksums LengthChecksums section size
4632Payload HashSHA-256 of payload
781Compression Level0-13
7949ReservedFuture use

Magic Number

zig
pub const MAGIC: [4]u8 = .{ 'Z', 'I', 'G', 'X' };

Flags

BitDescription
0Signed
1Encrypted
2-31Reserved

Metadata Section

Metadata is stored as key-value pairs:

FieldSizeDescription
Key Length2 bytesLittle-endian
Key DatavariableUTF-8 string
Value Length4 bytesLittle-endian
Value DatavariableUTF-8 string

Standard Metadata Keys

KeyDescription
formatAlways "zigx"
format_versionVersion string
created_atUnix timestamp
file_countNumber of files
file_typesFile type statistics

Checksums Section

Each file has an entry:

FieldSizeDescription
Path Length2 bytesLittle-endian
Path DatavariableUTF-8 string
File Size8 bytesLittle-endian
SHA-256 Hash32 bytesFile checksum

Compressed Payload

The payload starts with a compression header:

FieldSizeDescription
Magic4 bytesZXCM
Version1 byteCompression version
EntriesvariableCompressed files

Compression Version

VersionAlgorithm
1Zstandard (zstd) - levels 1-19, frame format with content size

File Entry Format

FieldSizeDescription
Path Length4 bytesCompressed path size
Path DatavariableCompressed path
Original Size8 bytesUncompressed size
Compressed Size4 bytesCompressed size
CRC324 bytesIntegrity check
ContentvariableCompressed data

Versioning Strategy

ZIGX uses two version numbers:

Format Version

Tracks changes to the archive structure:

zig
pub const FORMAT_VERSION: u16 = 0x0001;  // v1
  • Breaking changes increment major version
  • New features increment minor version

Compression Version

Tracks changes to the compression algorithm:

zig
pub const COMPRESSION_VERSION: u8 = 1;  // Zstandard (zstd)
VersionAlgorithmNotes
1Zstandard (zstd)Current, levels 1-19

This allows:

  • Algorithm updates without format changes
  • Backward compatibility
  • Clear capability tracking

Reading Archive Information

zig
const zigx = @import("zigx");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    var info = try zigx.getArchiveInfo("archive.zigx", allocator);
    defer info.deinit();

    std.debug.print("Format Version:      v{d}\n", .{info.format_version});
    std.debug.print("Compression Version: v{d}\n", .{info.compression_version});
    std.debug.print("File Count:          {d}\n", .{info.file_count});
    std.debug.print("Original Size:       {d} bytes\n", .{info.original_size});
    std.debug.print("Compressed Size:     {d} bytes\n", .{info.compressed_size});
}

File Extension

The recommended extension is .zigx:

myproject.zigx
bundle.zigx
release-v0.0.1.zigx

MIME Type

application/x-zigx

Next Steps

Released under the Apache License 2.0.