gzran

package module
v0.0.0-...-d8891e2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: Apache-2.0 Imports: 7 Imported by: 1

README

This code was forked from https://github.com/timpalpant/gzran

The original code is based on the c library, zran, by Mark Adler: https://github.com/madler/zlib/blob/master/examples/zran.c

Documentation

Index

Constants

View Source
const DefaultIndexInterval = 1024 * 1024 // 1 MB

DefaultIndexInterval is how often the reader will save decompressor state by default.

Variables

View Source
var (
	// ErrInvalidSeek is returned if attempting to seek prior to beginning of the file.
	ErrInvalidSeek = errors.New("zseek: attempting to seek before beginning of file")
	// ErrUnimplementedSeek is returned if attempting to seek from the end of the file.
	ErrUnimplementedSeek = errors.New("zseek: seek from SeekEnd is not implemented")
)

Functions

This section is empty.

Types

type DReader

type DReader struct {
	Index // valid after NewReader
	// contains filtered or unexported fields
}

A Reader is an io.Reader that can be read to retrieve uncompressed data from a raw deflated (compressed) file, from a ZIP archive.

Clients should treat data returned by Read as tentative until they receive the io.EOF marking the end of the data.

func NewDReader

func NewDReader(r io.ReadSeeker) (*DReader, error)

func NewDReaderInterval

func NewDReaderInterval(r io.ReadSeeker, indexInterval int64) (*DReader, error)

func (*DReader) Close

func (z *DReader) Close() error

Close closes the Reader. It does not close the underlying io.Reader. In order for the GZIP checksum to be verified, the reader must be fully consumed until the io.EOF.

func (*DReader) Read

func (z *DReader) Read(p []byte) (n int, err error)

Read implements io.Reader, reading uncompressed bytes from its underlying Reader.

func (*DReader) Seek

func (z *DReader) Seek(offset int64, whence int) (position int64, err error)

Seek implements io.Seeker. The gzip file will be decompressed as needed to seek forward, building an index of offsets as it does so. Subsequent calls to seek will use the index to skip data more efficiently. Seeking from the end of the file is not implemented and will return ErrUnimplementedSeek.

type Index

type Index []Point

Index collects decompressor state at offset Points. gzseek.Reader adds points to the index on the fly as decompression proceeds.

func LoadIndex

func LoadIndex(r io.Reader) (Index, error)

LoadIndex deserializes an Index from the given io.Reader.

func (Index) WriteTo

func (idx Index) WriteTo(w io.Writer) error

WriteTo serializes the index to the given io.Writer. It can be deserialized with LoadIndex.

type Point

type Point struct {
	CompressedOffset   int64
	UncompressedOffset int64
	DecompressorState  []byte
}

Point holds the decompressor state at a given offset within the uncompressed data.

Directories

Path Synopsis
internal
flate
Package flate implements the DEFLATE compressed data format, described in RFC 1951.
Package flate implements the DEFLATE compressed data format, described in RFC 1951.

Jump to

Keyboard shortcuts

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