Documentation
¶
Overview ¶
Package zlib implements reading and writing of zlib format compressed data, as specified in RFC 1950.
This is a parallel drop-in replacement for "compress/zlib". Writes to a Writer are split into blocks and compressed in parallel using DEFLATE.
Index ¶
Constants ¶
const ( NoCompression = flate.NoCompression BestSpeed = flate.BestSpeed BestCompression = flate.BestCompression DefaultCompression = flate.DefaultCompression ConstantCompression = flate.ConstantCompression HuffmanOnly = flate.HuffmanOnly )
These constants are copied from the flate package, so that code that imports "compress/zlib" does not also have to import "compress/flate".
Variables ¶
var ( // ErrChecksum is returned when reading ZLIB data that has an invalid checksum. ErrChecksum = errors.New("zlib: invalid checksum") // ErrDictionary is returned when reading ZLIB data that has an invalid dictionary. ErrDictionary = errors.New("zlib: invalid dictionary") // ErrHeader is returned when reading ZLIB data that has an invalid header. ErrHeader = errors.New("zlib: invalid header") )
Functions ¶
func NewReader ¶
func NewReader(r io.Reader) (io.ReadCloser, error)
NewReader creates a new ReadCloser reading the given reader. The implementation buffers input and may read more data than necessary from r. It is the caller's responsibility to call Close on the ReadCloser when done.
The io.ReadCloser returned by NewReader also implements Resetter.
func NewReaderDict ¶
NewReaderDict is like NewReader but uses a preset dictionary. NewReaderDict ignores the dictionary if the compressed data does not refer to it. If the compressed data refers to a different dictionary, NewReaderDict returns ErrDictionary.
The ReadCloser returned by NewReaderDict also implements Resetter.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader is an io.ReadCloser that can be read to retrieve uncompressed data from a zlib-format compressed file.
func NewReaderN ¶
NewReaderN creates a new Reader reading the given reader with custom block settings.
func NewReaderNDict ¶
NewReaderNDict creates a new Reader reading the given reader with a preset dictionary and custom block settings.
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) 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 {
// contains filtered or unexported fields
}
A Writer is an io.WriteCloser. Writes to a Writer are compressed and written to w.
func NewWriter ¶
NewWriter creates a new Writer. Writes to the returned Writer are compressed and written to w.
It is the caller's responsibility to call Close on the Writer when done. Writes may be buffered and not flushed until Close.
func NewWriterLevel ¶
NewWriterLevel is like NewWriter but specifies the compression level instead of assuming DefaultCompression.
The compression level can be DefaultCompression, NoCompression, HuffmanOnly or any integer value between BestSpeed and BestCompression inclusive. The error returned will be nil if the level is valid.
func NewWriterLevelDict ¶
NewWriterLevelDict is like NewWriterLevel but specifies a dictionary to compress with.
The dictionary may be nil. If not, its contents should not be modified until the Writer is closed.
func (*Writer) Close ¶
Close closes the Writer, flushing any unwritten data to the underlying io.Writer, but does not close the underlying io.Writer.
func (*Writer) Flush ¶
Flush flushes any pending compressed data to the underlying writer.
In the terminology of the zlib library, Flush is equivalent to Z_SYNC_FLUSH.
func (*Writer) Reset ¶
Reset clears the state of the Writer z such that it is equivalent to its initial state from NewWriterLevel or NewWriterLevelDict, but instead writing to w.
func (*Writer) SetConcurrency ¶
SetConcurrency can finetune the concurrency level if needed.
With this you can control the approximate size of your blocks, as well as how many you want to be processing in parallel.
Default values for this is SetConcurrency(defaultBlockSize, runtime.GOMAXPROCS(0)), meaning blocks are split at 1 MB and up to the number of CPU threads can be processing at once before the writer blocks.
func (*Writer) UncompressedSize ¶
UncompressedSize will return the number of bytes written.