zstdidx

package
v0.7.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Version = 1

Version of the on-disk index format.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame struct {
	CompOff  int64
	CompSize int64
	OutOff   int64
	OutSize  int64
}

Frame is one zstd frame: where its compressed bytes are and how much output it produces.

type Index

type Index struct {
	FileSize int64
	TotalOut int64
	Frames   []Frame
	Entries  []gzipidx.Entry
}

Index is a built index: the frame table plus the tar directory inside the stream.

func Build

func Build(path string) (*Index, error)

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.

func Load

func Load(path string) (*Index, error)

Load reads an index written by Save.

func (*Index) Lookup

func (ix *Index) Lookup(name string) (gzipidx.Entry, bool)

Lookup finds a tar member by exact name.

func (*Index) Save

func (ix *Index) Save(path string) error

Save writes the index in a compact binary form.

func (*Index) Seekable

func (ix *Index) Seekable() bool

Seekable reports whether a read can start away from the first frame: with more than one frame it can, because frames decode independently.

func (*Index) Usable

func (ix *Index) Usable() bool

Usable reports whether the index can serve a listing.

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

func OpenReader(path string, ix *Index) (*Reader, error)

OpenReader opens path with a loaded index.

func (*Reader) Close

func (r *Reader) Close() error

Close releases the file.

func (*Reader) Index

func (r *Reader) Index() *Index

Index returns the 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL