Recursive AI

Choosing codecs for a small binary

All onearchive docs

Archive and the per-format readers and writers reach codecs only through a registry. By default nothing needs configuring: the first time an archive needs a codec, every codec is registered, so every format and method works, and the app carries every codec.

An app that needs a small NativeAOT or trimmed binary turns the default off and registers what it uses:

XML
<ItemGroup>
  <RuntimeHostConfigurationOption Include="RecursiveAI.OneArchive.AllCodecs" Value="false" Trim="true" />
</ItemGroup>
C#
ArchiveCodecs.AddZstd();   // .zst and .tar.zst; AddLz4, AddDeflate, AddDeflate64, AddBZip2, AddLzma, AddXz,
                           // AddLzip, AddBrotli, AddLzx and AddFilters register the others

Without the trimmer the switch can be set before the first archive is touched with AppContext.SetSwitch("RecursiveAI.OneArchive.AllCodecs", false).

With the default off, an archive that needs a codec the app did not register fails with an ArchiveUnsupportedException naming the format, the method and the ArchiveCodecs.Add... call that fixes it. It is never skipped or truncated.

Which call serves what:

NeedRegister
.zst, .tar.zst, zip method 93, 7z ZstandardAddZstd
.lz4, .tar.lz4AddLz4
.gz, .tar.gz, zip method 8 (the zip writer's default), 7z Deflate, cabinet MSZIPAddDeflate
zip method 9, 7z Deflate64AddDeflate64
.bz2, .tar.bz2, zip method 12, 7z BZip2AddBZip2
zip method 14, 7z LZMA and LZMA2, 7z compressed headersAddLzma
.xz, .tar.xz, zip method 95AddXz
.lz, .tar.lzAddLzip
.br, .tar.br (and brotli's dictionary)AddBrotli
cabinet LZX foldersAddLzx
7z branch converters and deltaAddFilters

The smoke app smoke/aot-trim-slim reads and writes only .tar.zst this way; build/ci.sh aot publishes it with NativeAOT and checks that no other codec's types and not brotli's dictionary are in the binary.