flate

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package flate provides a reader and writer that propagate calls to Flush and Close.

Index

Constants

View Source
const (
	NoCompression      = flate.NoCompression
	BestSpeed          = flate.BestSpeed
	BestCompression    = flate.BestCompression
	DefaultCompression = flate.DefaultCompression
	HuffmanOnly        = flate.HuffmanOnly
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteReadCloser

type ByteReadCloser interface {
	io.ReadCloser
	io.ByteReader
}

type ReadResetCloser

type ReadResetCloser interface {
	io.Reader
	io.Closer
	Resetter
}

func ReadBytes

func ReadBytes(b []byte, dict []byte) ReadResetCloser

ReadBytes returns a reader for reading DEFLATE-compressed bytes from an input slice. b is the input slice of compressed bytes. dict is the initial dictionary, if one exists.

type Reader

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

func NewReader

func NewReader(r ByteReadCloser) *Reader

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. It is the caller's responsibility to call Close on the ReadCloser when finished reading.

The ReadCloser returned by NewReader also implements Resetter.

func NewReaderDict

func NewReaderDict(r ByteReadCloser, dict []byte) *Reader

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.

func ReadFile

func ReadFile(path string, dict []byte, bufferSize int) (*Reader, error)

ReadFile returns a reader for reading bytes from a DEFLATE-compressed file.

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

func (*Reader) Reset

func (r *Reader) Reset(reader ByteReadCloser, dict []byte) error

type Resetter

type Resetter interface {
	Reset(r io.Reader, dict []byte) 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 Writer

type Writer struct {
	*flate.Writer
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.WriteCloser) (*Writer, error)

NewWriter returns a new Writer compressing data at the default level.

func NewWriterDict

func NewWriterDict(w io.WriteCloser, level int, dict []byte) (*Writer, error)

NewWriterDict is like NewWriter but initializes the new Writer with a preset dictionary. The returned Writer behaves as if the dictionary had been written to it without producing any compressed output. The compressed data written to w can only be decompressed by a Reader initialized with the same dictionary.

func NewWriterLevel

func NewWriterLevel(w io.WriteCloser, level int) (*Writer, error)

NewWriterLevel returns a new Writer compressing data at the given level. Following zlib, levels range from 1 (BestSpeed) to 9 (BestCompression); higher levels typically run slower but compress more. Level 0 (NoCompression) does not attempt any compression; it only adds the necessary DEFLATE framing. Level -1 (DefaultCompression) uses the default compression level. Level -2 (HuffmanOnly) will use Huffman compression only, giving a very fast compression for all types of input, but sacrificing considerable compression efficiency.

If level is in the range [-2, 9] then the error returned will be nil. Otherwise the error returned will be non-nil.

func WriteFile

func WriteFile(path string, bufferSize int) (*Writer, error)

WriteFile returns a Writer for writing to a local file

func (*Writer) Close

func (w *Writer) Close() error

Close closes the flate.Writer, and then flushes and closes the underlying WriteCloser.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush flushes any pending data to the underlying writer. It is useful mainly in compressed network protocols, to ensure that a remote reader has enough data to reconstruct a packet. Flush does not return until the data has been written. Calling Flush when there is no pending data still causes the Writer to emit a sync marker of at least 4 bytes. If the underlying writer returns an error, Flush returns that error.

In the terminology of the zlib library, Flush is equivalent to Z_SYNC_FLUSH.

Jump to

Keyboard shortcuts

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