flate

package
v0.0.0-...-6f22675 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package flate implements the DEFLATE compressed data format, described in RFC 1951. The gzip and zlib packages implement access to DEFLATE-based file formats.

Index

Constants

View Source
const (
	NoCompression      = 0
	BestSpeed          = 1
	BestCompression    = 9
	DefaultCompression = -1

	// HuffmanOnly disables Lempel-Ziv match searching and only performs Huffman
	// entropy encoding. This mode is useful in compressing data that has
	// already been compressed with an LZ style algorithm (e.g. Snappy or LZ4)
	// that lacks an entropy encoder. Compression gains are achieved when
	// certain bytes in the input stream occur more frequently than others.
	//
	// Note that HuffmanOnly produces a compressed output that is
	// RFC 1951 compliant. That is, any valid DEFLATE decompressor will
	// continue to be able to decompress this output.
	HuffmanOnly = -2
)

Variables

This section is empty.

Functions

func NewReader

func NewReader(r io.Reader) io.ReadCloser

NewReader returns a new ReadCloser that can be used to read the uncompressed version of r. If r does not also implement io.ByteReader, the decompressor may read more data than necessary from r. The reader returns io.EOF after the final block in the DEFLATE stream has been encountered. Any trailing data after the final block is ignored.

The ReadCloser returned by NewReader also implements Resetter.

func NewReaderDict

func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser

NewReaderDict is like NewReader but initializes the reader with a preset dictionary. The returned Reader behaves as if the uncompressed data stream started with the given dictionary, which has already been read. NewReaderDict is typically used to read data compressed by NewWriterDict.

The ReadCloser returned by NewReader also implements Resetter.

Types

type Checkpoint

type Checkpoint struct {
	// TODO: separate these from the rest
	In  int64 `json:"in,omitempty"`
	Out int64 `json:"out,omitempty"`

	// bits?
	B    uint32 `json:"b,omitempty"`
	NB   uint   `json:"nb,omitempty"`
	Hist []byte `json:"hist,omitempty"`

	// Trying random stuff...
	WrPos int  `json:"wrpos,omitempty"`
	RdPos int  `json:"rdpos,omitempty"`
	Full  bool `json:"full,omitempty"`

	// If there is no Hist, we can avoid writing the file.
	Empty bool `json:"empty,omitempty"`

	// Optional gzip header.
	GzipHeader *Header `json:"header,omitempty"`
}

func (*Checkpoint) BytesRead

func (c *Checkpoint) BytesRead() int64

func (*Checkpoint) BytesWritten

func (c *Checkpoint) BytesWritten() int64

func (*Checkpoint) History

func (c *Checkpoint) History() []byte

func (*Checkpoint) IsEmpty

func (c *Checkpoint) IsEmpty() bool

func (*Checkpoint) SetHistory

func (c *Checkpoint) SetHistory(b []byte)

type CorruptInputError

type CorruptInputError int64

A CorruptInputError reports the presence of corrupt input at a given offset.

func (CorruptInputError) Error

func (e CorruptInputError) Error() string

type Decompressor

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

Decompress state.

func Continue

func Continue(r io.Reader, from *Checkpoint, span int64, updates chan<- *Checkpoint) *Decompressor

func NewReaderWithSpans

func NewReaderWithSpans(r io.Reader, span int64, start int64, updates chan<- *Checkpoint) *Decompressor

NewReaderWithSpans is a hack.

func (*Decompressor) Close

func (f *Decompressor) Close() error

func (*Decompressor) Read

func (f *Decompressor) Read(b []byte) (int, error)

func (*Decompressor) Reset

func (f *Decompressor) Reset(r io.Reader, dict []byte, roffset int64) error

func (*Decompressor) ResetTo

func (f *Decompressor) ResetTo(from *Checkpoint) (int64, error)

func (*Decompressor) ToRead

func (f *Decompressor) ToRead() int64

func (*Decompressor) Woffset

func (f *Decompressor) Woffset() int64
type Header struct {
	Comment string     `json:"comment,omitempty"`
	Extra   []byte     `json:"extra,omitempty"`
	ModTime *time.Time `json:"modtime,omitempty"`
	Name    string     `json:"name,omitempty"`
	OS      *byte      `json:"os,omitempty"`
}

type InternalError

type InternalError string

An InternalError reports an error in the flate code itself.

func (InternalError) Error

func (e InternalError) Error() string

type ReadError deprecated

type ReadError struct {
	Offset int64 // byte offset where error occurred
	Err    error // error returned by underlying Read
}

A ReadError reports an error encountered while reading input.

Deprecated: No longer returned.

func (*ReadError) Error

func (e *ReadError) Error() string

type Reader

type Reader interface {
	io.Reader
	io.ByteReader
}

The actual read interface needed by NewReader. If the passed in io.Reader does not also have ReadByte, the NewReader will introduce its own buffering.

type Resetter

type Resetter interface {
	// Reset discards any buffered data and resets the Resetter as if it was
	// newly initialized with the given reader.
	Reset(r io.Reader, dict []byte, roffset int64) error
}

Resetter resets a ReadCloser returned by NewReader or NewReaderDict to switch to a new underlying Reader. This permits reusing a ReadCloser instead of allocating a new one.

type Trailer

type Trailer struct {
	Digest uint32 `json:"crc32,omitempty"`
	Size   uint32 `json:"isize,omitempty"`
}

type Woffseter

type Woffseter interface {
	Woffset() int64
}

Gross, sorry.

type WriteError deprecated

type WriteError struct {
	Offset int64 // byte offset where error occurred
	Err    error // error returned by underlying Write
}

A WriteError reports an error encountered while writing output.

Deprecated: No longer returned.

func (*WriteError) Error

func (e *WriteError) Error() string

Jump to

Keyboard shortcuts

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