XzSeekable 0.2.0

dotnet add package XzSeekable --version 0.2.0
                    
NuGet\Install-Package XzSeekable -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XzSeekable" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XzSeekable" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="XzSeekable" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add XzSeekable --version 0.2.0
                    
#r "nuget: XzSeekable, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package XzSeekable@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=XzSeekable&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=XzSeekable&version=0.2.0
                    
Install as a Cake Tool

XzSeekable

Random-access (seekable) reading of xz (LZMA2) streams in .NET.

xz streams are normally forward-only: reading byte N means decompressing everything before it. XzSeekable gives you a standard seekable Stream over xz data using whichever of two mechanisms fits your input:

Native block index Custom checkpoint index
Input Multi-block .xz (written by xz -T, xz --block-size=, or pixz) — every block is independently decodable and the file's footer Index lists them Any single-block .xz stream, e.g. default xz output or a Clonezilla -z5 partition image
Setup cost None — the block index is read from the footer instantly One full sequential decode to build a verified LZMA2-chunk checkpoint index (persist it; later opens are instant)
Seek cost Decode ≤ 1 block Decode from the nearest checkpoint (bounded by the index's span size)

Everything is managed code (a vendored xz/LZMA2 decoder from SharpCompress) — no native binaries. Targets netstandard2.0 and net8.0.

Quick start

using XzSeekable;

// Multi-block .xz: the native block index is read from the footer - no build step.
using var compressed = File.OpenRead(@"C:\images\disk.img.xz");
using var stream = XzBlockIndexedStream.Open(compressed);   // throws if the file is single-block

stream.Position = 123_456_789;          // seek anywhere
var buffer = new byte[4096];
var read = stream.Read(buffer, 0, buffer.Length);
using XzSeekable;

// Single-block .xz (default xz output): build a checkpoint index once, then seek freely.
// The build is one sequential decode; the index persists to disk, so later opens are instant.
// An interrupted build resumes from its last sealed checkpoint on the next call.
using var compressed = File.OpenRead(@"C:\images\partition.img.xz");
using var index = XzIndex.LoadOrBuild(compressed, @"C:\images\partition.img.xzi");
using var stream = new XzIndexedStream(compressed, index);

stream.Position = 123_456_789;          // decodes from the nearest checkpoint, not from byte 0

How multi-block seeking works

An .xz stream ends with an Index recording every block's compressed and uncompressed size, and each block is a self-contained LZMA2 stream (its dictionary resets at the block start). So a read at uncompressed offset O locates the containing block from the index, decodes that one block, and discards the bytes before O — cost bounded by the block size, not the file size. Only files written with more than one block are seekable this way; check XzBlockIndexedStream.Container.BlockCount.

How the checkpoint index works

A single-block .xz has no native index, so XzIndex.LoadOrBuild decodes the stream once and drops a checkpoint roughly every span (XzIndexOptions.TargetSpanBytes): the exact LZMA2 decoder state (probability tables, repeat distances, state index) plus a compressed snapshot of the dictionary window, so a resume is exact by construction. Runs of a constant byte are recorded as fill spans and served without touching the decoder at all. The build byte-verifies a sample of checkpoints with a shadow decoder (XzIndexOptions.VerifiedSampleSpans), streams sealed records to <index>.wip as it goes (flat memory, and an interrupted build resumes from its last sealed checkpoint), and finalises atomically. The persisted format is "XZSKIDX1"; the index is fingerprinted against the compressed stream and rebuilt automatically if it doesn't match. Window snapshots are inflated lazily — only when a read actually resumes at that checkpoint — so opening a large index is cheap.

License

MIT. Includes a vendored copy of xz/LZMA2 decoder source from SharpCompress (MIT). See LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 289 7/18/2026

Adds single-block .xz support: builds a verified LZMA2 chunk-checkpoint index (exact decoder-state resume points, streaming persistence with interrupted-build resume, lazy window loading, fill spans for constant-byte runs). Multi-block .xz continues to seek via the native block index with no build step.