gzip

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gzip implements reading of gzip format compressed files, as specified in RFC 1952. This implementation is lazy and skips header and trailer (including checksum). For this reason it is recommended that you have any other mechanism for framing the bytes.

Example (SampleData)
data, _ := sampleData()
fmt.Println(len(data), data)
Output:


117 [31 139 8 24 128 227 232 13 0 255 97 45 110 101 119 45 104 111 112 101 46 116 120 116 0 97 110 32 101 112 105 99 32 115 112 97 99 101 32 111 112 101 114 97 32 98 121 32 71 101 111 114 103 101 32 76 117 99 97 115 0 114 84 200 201 207 75 87 40 201 204 77 85 72 76 207 87 200 204 83 72 84 72 79 204 73 172 168 84 72 75 44 210 1 17 10 137 229 137 149 122 122 122 128 0 0 0 255 255 16 138 163 239 44 0 0 0]

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrChecksum is returned when reading GZIP data that has an invalid checksum.
	ErrChecksum = gzip.ErrChecksum
	// ErrHeader is returned when reading GZIP data that has an invalid header.
	ErrHeader = gzip.ErrHeader
)

Functions

This section is empty.

Types

type Pool

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

func (*Pool) Get

func (pool *Pool) Get(br ringbuf.RingBufferReader) (r *Reader, err error)

func (*Pool) Put

func (pool *Pool) Put(r *Reader)

type Reader

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

A Reader is an io.Reader that can be read to retrieve uncompressed data from a gzip-format compressed file.

In general, a gzip file can be a concatenation of gzip files, each with its own header. Reads from the Reader return the concatenation of the uncompressed data of each.

Example
var buf bytes.Buffer

if err := writeSampleData(&buf); err != nil {
	panic(err)
}

if err := writeSampleData(&buf); err != nil {
	panic(err)
}

// br := bufio.NewReader(&buf)
br := ringbuf.NewReader(&buf).LimitReader(buf.Len())
r, err := NewReader(br)

if err != nil {
	panic(err)
}

data, err := io.ReadAll(r)

if err != nil {
	panic(err)
}

fmt.Println(string(data))
Output:

A long time ago in a galaxy far, far away...A long time ago in a galaxy far, far away...

func NewReader

func NewReader(br ringbuf.RingBufferReader) (*Reader, error)

NewReader creates a new Reader reading the given reader. If r does not also implement io.ByteReader, the decompressor may read more data than necessary from r.

It is the caller's responsibility to call Close on the Reader when done.

func (*Reader) Close

func (z *Reader) Close() error

Close closes the Reader. It does not close the underlying io.Reader.

func (*Reader) Read

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

func (*Reader) Reader added in v0.6.0

func (z *Reader) Reader() ringbuf.RingBufferReader

func (*Reader) Reset

func (z *Reader) Reset(br ringbuf.RingBufferReader) error

Reset discards the Reader z's state and makes it equivalent to the result of its original state from NewReader, but reading from r instead. This permits reusing a Reader rather than allocating a new one.

Example
var buf bytes.Buffer

if err := writeSampleData(&buf); err != nil {
	panic(err)
}

r, err := NewReader(nil)

if err != nil {
	panic(err)
}

if err := r.Reset(nil); err != nil {
	panic(err)
}
Output:

TODO

Jump to

Keyboard shortcuts

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