ZXC

High-performance lossless compression, built for ultra-fast decode

Star


Migrating ZXC archives across format versions

ZXC 1.0.3. Generated from docs/MIGRATION.md; corrections are welcome as pull requests. If ZXC is useful to you, a star on GitHub helps others find it ( 544 so far).

Format v9 is frozen as of ZXC 1.0.0: every later release reads v9 archives, and a decoder for version N reads every version from 9 to N. Archives older than v9 (v5 to v8) are rejected with ZXC_ERROR_BAD_VERSION and take a one-time transcode.

Format Introduced by Headline change
v9 ZXC 0.15.x, kept by 1.0.x New header and block checksums, optional archive digest, seek table rebuilt, .zxd version 2
v8 ZXC 0.14.x Block sub-header 16 → 12 bytes; smaller section descriptors
v7 ZXC 0.13.x Huffman bits use the PivCo layout; new level 7 (ULTRA)
v6 ZXC 0.12.x NUM block removed; PAK renumbered type 3 → 2
v5 earlier —

Upgrading from 0.15.x takes no transcode, but the APIs and the CLI defaults change: see 0.15.x → 1.0.0.


0.15.x → 1.0.0 (format v9 unchanged)#

No archive migration. Archives and .zxd dictionaries read in both directions between 0.15.x and 1.0.0. Non-zero reserved bits and bytes are now rejected in file, block and .zxd headers (ZXC_ERROR_BAD_HEADER for a dictionary). 0.15.x writes zeros there, so only a third-party writer can be affected.

C API: option structs become context parameters#

This is a source and ABI break. The SOVERSION moves from 5 to 6, so binaries built against libzxc.so.5 must be rebuilt. The option structs and the opts arguments are gone: settings live on a context, set one at a time by identifier (zxc_cparam_t, zxc_dparam_t in zxc_opts.h). zxc_cctx_get_param() / zxc_dctx_get_param() read a setting back, zxc_cparam_bounds() / zxc_dparam_bounds() report its bounds, and ZXC_ERROR_BAD_PARAM (-20) is new. See API.md §6.1 and §9.

0.15.x 1.0.x
zxc_train_dict(...) zxc_dict_train_content(...) (same arguments)
zxc_train_dict_huf(...) zxc_dict_train_huf(...) (same arguments)
zxc_dict_id(dict, size, huf) zxc_dict_compute_id(dict, size, huf)
zxc_dict_get_id(buf, size) zxc_dict_read_id(buf, size)
uint64_t zxc_compress_bound(), zxc_compress_block_bound(), zxc_decompress_block_bound(), zxc_estimate_cctx_size() the same functions return size_t; 0 still means "too large for this platform"
— zxc_version_number(): MAJOR*10000 + MINOR*100 + PATCH of the loaded library (ZXC_VERSION_NUMBER for the headers)
— zxc_version_codename(): release code name of the loaded library (ZXC_VERSION_CODENAME for the headers)
zxc_compress(src, n, dst, cap, NULL) zxc_compress(src, n, dst, cap, 0) (0 = default level)
zxc_compress(src, n, dst, cap, &(zxc_compress_opts_t){.level = 5}) zxc_compress(src, n, dst, cap, 5)
zxc_compress(..., &(zxc_compress_opts_t){.level = 5, .block_size = 65536, .checksum_enabled = 1}) zxc_cctx* c = zxc_create_cctx();
zxc_cctx_set_param(c, ZXC_C_LEVEL, 5);
zxc_cctx_set_param(c, ZXC_C_BLOCK_SIZE, 65536);
zxc_cctx_set_param(c, ZXC_C_CHECKSUM, 1);
zxc_compress_cctx(c, src, n, dst, cap);
zxc_free_cctx(c);
zxc_decompress(src, n, dst, cap, NULL) zxc_decompress(src, n, dst, cap)
zxc_decompress(src, n, dst, cap, &(zxc_decompress_opts_t){.checksum_enabled = 1}) zxc_dctx* d = zxc_create_dctx();
zxc_dctx_set_param(d, ZXC_D_CHECKSUM, 1);
zxc_decompress_dctx(d, src, n, dst, cap);
zxc_free_dctx(d);
zxc_decompress_inplace(buf, cap, comp_size, opts) zxc_decompress_inplace(buf, cap, comp_size), or zxc_decompress_inplace_dctx(d, buf, cap, comp_size) with a configured d
zxc_create_cctx(&opts) zxc_create_cctx() then zxc_cctx_set_param() per setting
zxc_compress_cctx(c, src, n, dst, cap, &opts) zxc_compress_cctx(c, src, n, dst, cap)
zxc_compress_block(c, ..., &opts) / zxc_decompress_block(d, ..., &opts) / zxc_decompress_block_safe(d, ..., &opts) same calls without the last argument
zxc_decompress_dctx(d, src, n, dst, cap, &opts) zxc_decompress_dctx(d, src, n, dst, cap)
.dict, .dict_size, .dict_huf zxc_cctx_set_dict(c, dict, size, huf) / zxc_dctx_set_dict(d, dict, size, huf); NULL dict detaches
.progress_cb, .user_data zxc_cctx_set_progress(c, cb, ud) / zxc_dctx_set_progress(d, cb, ud)
.n_threads ZXC_C_THREADS / ZXC_D_THREADS
.seekable = 1 zxc_cctx_set_param(c, ZXC_C_SEEKABLE, 1)
zxc_init_static_cctx(ws, sz, &(zxc_compress_opts_t){.level = L, .block_size = B, .checksum_enabled = 1}) zxc_cctx* c = zxc_init_static_cctx(ws, sz, B, L);
zxc_cctx_set_param(c, ZXC_C_CHECKSUM, 1);
zxc_stream_compress(fin, fout, &opts) / zxc_stream_decompress(fin, fout, &opts) zxc_stream_compress(fin, fout, c) / zxc_stream_decompress(fin, fout, d) (NULL still means defaults)
zxc_cstream_create(&opts) / zxc_dstream_create(&opts) zxc_cstream_create(c) / zxc_dstream_create(d)
zxc_compress_opts_size() / zxc_decompress_opts_size() gone; use zxc_cparam_bounds() / zxc_dparam_bounds()

Behaviour changes beyond the rewrite:

CLI behaviour#

Bindings#

The bindings move from wrappers/ to bindings/. Their high-level calls keep their shape, except:


v8 → v9 (ZXC 0.15.x)#

The compressed data is unchanged; the break is in the integrity fields and the seek table. Tools that parse archives directly need these changes:

Windows archives (0.15.x)#

The archives are built with MinGW-w64 (UCRT) and ship bin/libzxc.dll, its MinGW import library and lib/libzxc.def. The MSVC static lib/zxc.lib of 0.14.x is gone, and the archive's CMake package and libzxc.pc target MinGW. MSVC projects build an import library (lib /def:lib\libzxc.def /out:zxc.lib /machine:x64, or arm64) or build zxc from source for a static library. A CMake MSVC build names the DLL libzxc.dll (0.14.x: zxc.dll) and keeps the import library zxc.lib.

CLI output (0.15.x)#

Older format breaks#

The table at the top gives the headline; the recipes below apply to each.


Do I need to migrate?#

Only if you have archives from v8 or earlier and want to read them with v9 tools or standardize on v9. The old build still reads its own archives, so there is no rush.

Check an archive's format version#

The version is the byte at offset 0x04 of the file header (zxc -V reports the tool version):

xxd -s 4 -l 1 archive.zxc      # -> "05" = v5 ... "08" = v8, "09" = v9

Migrate: transcode with the old build, recompress with v9#

zxc-old reads the old format and zxc-new is ZXC 0.15.x or later:

zxc-old -dc old.zxc | zxc-new -z -c > new.zxc

The archive does not record its encoding level, so pick the new options explicitly:

zxc-old -dc old.zxc | zxc-new -z -6 -c > new.zxc     # densest fast-decode tier
zxc-old -dc old.zxc | zxc-new -z -7 -c > new.zxc     # ULTRA, densest level
zxc-old -dc old.zxc | zxc-new -z -N -c > new.zxc     # no checksums
zxc-old -dc old.zxc | zxc-new -z -B 1M -c > new.zxc  # 1 MB blocks
zxc-old -dc old.zxc | zxc-new -z -S -c > new.zxc     # keep it seekable

An archive compressed with a dictionary needs it on the old side (zxc-old -dc -D dict.zxd old.zxc | ...), and a version-2 dictionary on the new side.

Without a pipe, and in bulk:

zxc-old -dc old.zxc > tmp.raw && zxc-new -z -c tmp.raw > new.zxc && rm tmp.raw

for f in *.zxc; do
    zxc-old -dc "$f" | zxc-new -z -c > "migrated/$f" || echo "FAILED: $f"
done

Migrating a dictionary#

A v9 build rejects a version-1 .zxd (0.14.x) with ZXC_ERROR_BAD_VERSION, and no tool upgrades one in place. There are two routes.

Retrain, the simple one. The new dictionary gets its own dict_id:

zxc-new --train samples/* -o dict-v9.zxd
zxc-old -dc -D dict-v8.zxd old.zxc | zxc-new -z -D dict-v9.zxd -c > new.zxc

Convert byte for byte to keep the content, the shared Huffman table and the dict_id. Edit the 16-byte header (FORMAT.md § 12.4):

  1. set the version byte at 0x04 to 02;
  2. recompute the 2-byte header checksum of § 7.1 over the 16-byte header with bytes 0x0E..0x0F zeroed, and store it little-endian at 0x0E.

Verify the result#

zxc-new -t new.zxc                             # integrity check (v9)
diff <(zxc-old -dc old.zxc) <(zxc-new -dc new.zxc) && echo OK   # byte-identical output

Notes#