const (
NoCompression = flate.NoCompression
BestSpeed = flate.BestSpeed
BestCompression = flate.BestCompression
DefaultCompression = flate.DefaultCompression
)
These constants are copied from the flate package, so that code that imports "compress/zlib" does not also have to import "compress/flate".
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")
)
func NewReader(r io.Reader) (io.ReadCloser, error)
NewReader creates a new io.ReadCloser that satisfies reads by decompressing data read from r. 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.
▹ Example
func NewReaderDict(r io.Reader, dict []byte) (io.ReadCloser, error)
NewReaderDict is like NewReader but uses a preset dictionary. NewReaderDict ignores the dictionary if the compressed data does not refer to it.
type Writer struct {
// contains filtered or unexported fields
}
A Writer takes data written to it and writes the compressed form of that data to an underlying writer (see NewWriter).
func NewWriter(w io.Writer) *Writer
NewWriter creates a new Writer that satisfies writes by compressing data written to w.
It is the caller's responsibility to call Close on the WriteCloser when done. Writes may be buffered and not flushed until Close.
▹ Example
func NewWriterLevel(w io.Writer, level int) (*Writer, error)
NewWriterLevel is like NewWriter but specifies the compression level instead of assuming DefaultCompression.
The compression level can be DefaultCompression, NoCompression, or any integer value between BestSpeed and BestCompression inclusive. The error returned will be nil if the level is valid.
func NewWriterLevelDict(w io.Writer, level int, dict []byte) (*Writer, error)
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 (z *Writer) Close() error
Calling Close does not close the wrapped io.Writer originally passed to NewWriter.
func (z *Writer) Flush() error
Flush flushes the Writer to its underlying io.Writer.
func (z *Writer) Write(p []byte) (n int, err error)
Write writes a compressed form of p to the underlying io.Writer. The compressed bytes are not necessarily flushed until the Writer is closed or explicitly flushed.