Documentation
¶
Overview ¶
Package zstdidx gives a zstd-compressed tar the same random access a gzip one gets from gzipidx: one pass records every member's offset and header fields, and reads then start at a frame boundary instead of at byte zero.
The two formats differ in one decisive way. A deflate stream restarts at a block boundary because its whole state is a 32 KiB window, so gzipidx can put checkpoints anywhere. A zstd block needs the decoder's window — up to 128 MiB — which is not worth storing, so the only restart points are frame boundaries, and a frame decodes independently of the others. Writers that split their output into frames therefore give full random access: pzstd, the zstd seekable format and containerd's zstd-chunked layers all do. The `zstd` CLI and `tar --zstd` write a single frame, where the frame table has one entry: the member directory still makes every listing instant and reading a member costs one decode instead of two, because the directory is known without walking the stream again.
Index ¶
Constants ¶
const Version = 1
Version of the on-disk index format.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Frame ¶
Frame is one zstd frame: where its compressed bytes are and how much output it produces.
type Index ¶
Index is a built index: the frame table plus the tar directory inside the stream.
func Build ¶
Build scans a zstd file once: the compressed pass records the frame table, the decode pass records the tar directory. Decoding frame by frame doubles as a check on the frame table — a wrong extent fails to decode — and falls back to one unseekable frame covering the file when that happens.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader serves decompressed bytes from an output offset, restarting at the frame that holds it.
func OpenReader ¶
OpenReader opens path with a loaded index.
func (*Reader) ReadAt ¶
func (r *Reader) ReadAt(outOff int64) (io.ReadCloser, error)
ReadAt returns a reader positioned at an output offset. With several frames the decompressor starts at the frame holding that offset and walks on through the following ones, because a tar member can straddle a frame boundary; a single-frame stream starts at the beginning, which is still one pass.