Extract .cab files; Quantum and split files aren’t supported. The zip includes sample.cab.
dotnet add package RecursiveAI.OneArchiveRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneArchive; Archive.Extract("sample.cab", "extracted"); Console.WriteLine("Extracted hello.txt");
Extracted hello.txtUnzip the example, then dotnet run.
The full program
The included cabinet contains one stored file, hello.txt:
Hello from CAB!That text ends with a newline. This generated fixture has no third-party content. The program lists the entry, applies a 4,096-byte total limit and a 1,024-byte per-file check, extracts it, and compares its SHA-256 hash with the expected text. It explicitly allows overwriting the output so you can run the example again.
using RecursiveAI.OneArchive; using System.Security.Cryptography; var options = new ArchiveExtractOptions { Limits = new ArchiveLimits { MaxTotalSize = 4096, MaxEntryCount = 10 }, Existing = ExistingFilePolicy.Overwrite }; using var archive = Archive.Open("sample.cab", options); foreach (var entry in archive.Entries) { if (entry.Size > 1024) throw new InvalidDataException("Entry exceeds 1024 bytes."); Console.WriteLine($"{entry.Name}: {entry.Size} bytes"); } archive.Extract("output", options); byte[] actual = File.ReadAllBytes("output/hello.txt"); byte[] expected = "Hello from CAB!\n"u8.ToArray(); if (!SHA256.HashData(actual).AsSpan().SequenceEqual(SHA256.HashData(expected))) throw new InvalidDataException("Extracted content differs."); Console.WriteLine("SHA-256 matches expected content"); Console.Write(System.Text.Encoding.UTF8.GetString(actual));
hello.txt: 16 bytes SHA-256 matches expected content Hello from CAB!
The snippet at the top refuses existing destination files by default; unsupported compression or split data raises ArchiveUnsupportedException, and extraction is not a transaction that rolls back earlier files.
Variations
List files without extracting
Run this against the included sample.cab:
using RecursiveAI.OneArchive; using var archive = Archive.Open("sample.cab"); foreach (var entry in archive.Entries) Console.WriteLine($"{entry.Name}: {entry.Size} bytes");
hello.txt: 16 bytesRelated recipes
The short answer
Call Archive.Extract("sample.cab", "extracted") from RecursiveAI.OneArchive. The API detects the cabinet format and writes its files under the destination directory. You do not need to launch a command-line extraction utility or mount the cabinet.
CAB reading in version 1.2.0 supports stored folders, MSZIP, and LZX. It does not write cabinets. Quantum compression, files continued between cabinets, and data blocks continued between cabinets are unsupported. Those distinctions matter when choosing a reader for an existing installer: the .cab extension alone does not tell you whether its contents use a supported method.
How can I extract a CAB file?
For a trusted small cabinet, use the snippet at the top and replace the two paths with your input and destination. The sample needs no external files beyond the included cabinet. The full program adds a listing and checks before extraction, then reads the actual destination file to confirm its contents.
For application input, choose an ArchiveLimits policy. The full program restricts entry count and total size through that policy and separately rejects entries larger than its per-file allowance before extracting anything. MaxTotalSize applies to declared sizes while listing. It is not a per-entry size property: the explicit loop supplies that additional application rule.
The extraction API rejects unsafe paths by default, including traversal outside the destination. Leave those defaults in place rather than concatenating stored file names onto disk paths yourself. Existing files also cause failure unless you explicitly choose another policy. The full program chooses ExistingFilePolicy.Overwrite only to make repeated runs of this known sample convenient; omit it when unexpected replacement would be a problem.
CAB data is organized into folders, which are compression streams containing file data, rather than independent compressed streams for every entry. The cabinet reader documentation explains that reading files in table order costs one pass, while going backward decodes from the folder’s beginning again. Listing first and extracting in archive order avoids repeatedly reopening earlier files.
What can I do to fix the “Failed to extract cab” error?
Check the underlying exception rather than treating every failure as a damaged download. ArchiveUnsupportedException can mean a valid cabinet uses Quantum compression or split-cabinet data that this reader cannot decode. A continued file can appear in the listing but still fail when you try to open its content. Finding the next cabinet does not add split-cabinet support to this version.
CompressionFormatException indicates a format problem such as inconsistent block sizes or a checksum mismatch. The reader checks nonzero CFDATA checksums by default; a zero checksum is not checked. MSZIP blocks must decode to the declared size, and LZX frames must obey the supported frame layout. Disabling checksum verification does not add support for a compression method or a split file.
Also distinguish resource-policy failures from malformed data. An archive can be valid but exceed your configured total size, entry count, path length, expansion ratio, or window limit. Raise a limit only when it matches the files your application actually intends to accept. A successful listing alone does not prove that every compressed payload can be read.
Use a fresh destination when investigating failures. Extraction can already have written earlier entries before a later file fails. The sample’s expected-content hash checks one generated payload; it is not a guarantee about unrelated cabinet files. For full format details, including LZX window restrictions and filename decoding, see the pinned reader documentation.