compress

package
v0.0.0-...-99e3c09 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package compress decompresses a package member into a random-access io.ReaderAt.

The container readers in this module need random access over an io.ReaderAt, but the compressed inner members of a package are sequential streams. Decompress expands such a member to a temporary file once and serves it back as a *File, which is an io.ReaderAt whose File.Close removes the backing file. This is uniform across every codec, avoiding per-codec seekability handling. An uncompressed member is passed through directly — no copy and no temporary file.

The gzip and bzip2 codecs come from the standard library; xz and lzma are provided by github.com/ulikunitz/xz and zstd by github.com/klauspost/compress/zstd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec string

Codec identifies a compression format.

const (
	None  Codec = ""      // no (recognized) compression
	Gzip  Codec = "gzip"  //
	Bzip2 Codec = "bzip2" //
	Xz    Codec = "xz"    //
	Zstd  Codec = "zstd"  //
	Lzma  Codec = "lzma"  //
)

func Detect

func Detect(ra io.ReaderAt) (Codec, error)

Detect reports the compression codec of ra from its leading magic. A member with no recognized signature reports None.

type File

type File struct {
	// contains filtered or unexported fields
}

File is the decompressed content of a package member exposed as a random-access io.ReaderAt. Compressed members are backed by a temporary file that File.Close removes; an uncompressed member is served directly from the source, in which case File.Close is a no-op.

func Decompress

func Decompress(ra io.ReaderAt, size int64) (*File, error)

Decompress detects the codec of the size-byte member ra from its leading magic and expands it to a temporary file, returning the result as a random-access *File. An uncompressed member is passed through directly, without copying. The caller must File.Close the result to release any backing file.

func DecompressAs

func DecompressAs(ra io.ReaderAt, size int64, codec Codec) (*File, error)

DecompressAs expands the size-byte member ra using the named codec, returning the result as a random-access *File. None passes the member through directly, without copying. The caller must File.Close the result to release any backing file.

func (*File) Close

func (fl *File) Close() error

Close removes the backing temporary file, if any. It is a no-op for an uncompressed member served directly from its source.

func (*File) ReadAt

func (fl *File) ReadAt(p []byte, off int64) (int, error)

ReadAt implements io.ReaderAt.

func (*File) Size

func (fl *File) Size() int64

Size returns the decompressed length in bytes.

Jump to

Keyboard shortcuts

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