zlib

Imports

Imports #

"bufio"
"compress/flate"
"encoding/binary"
"errors"
"hash"
"hash/adler32"
"io"
"compress/flate"
"encoding/binary"
"fmt"
"hash"
"hash/adler32"
"io"

Constants & Variables

BestCompression const #

These constants are copied from the flate package, so that code that imports "compress/zlib" does not also have to import "compress/flate".

const BestCompression = flate.BestCompression

BestSpeed const #

These constants are copied from the flate package, so that code that imports "compress/zlib" does not also have to import "compress/flate".

const BestSpeed = flate.BestSpeed

DefaultCompression const #

These constants are copied from the flate package, so that code that imports "compress/zlib" does not also have to import "compress/flate".

const DefaultCompression = flate.DefaultCompression

ErrChecksum var #

ErrChecksum is returned when reading ZLIB data that has an invalid checksum.

var ErrChecksum = *ast.CallExpr

ErrDictionary var #

ErrDictionary is returned when reading ZLIB data that has an invalid dictionary.

var ErrDictionary = *ast.CallExpr

ErrHeader var #

ErrHeader is returned when reading ZLIB data that has an invalid header.

var ErrHeader = *ast.CallExpr

HuffmanOnly const #

These constants are copied from the flate package, so that code that imports "compress/zlib" does not also have to import "compress/flate".

const HuffmanOnly = flate.HuffmanOnly

NoCompression const #

These constants are copied from the flate package, so that code that imports "compress/zlib" does not also have to import "compress/flate".

const NoCompression = flate.NoCompression

zlibDeflate const #

const zlibDeflate = 8

zlibMaxWindow const #

const zlibMaxWindow = 7

Interfaces

Resetter interface #

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

Structs

Writer struct #

A Writer takes data written to it and writes the compressed form of that data to an underlying writer (see NewWriter).

type Writer struct {
w io.Writer
level int
dict []byte
compressor *flate.Writer
digest hash.Hash32
err error
scratch [4]byte
wroteHeader bool
}

reader struct #

type reader struct {
r flate.Reader
decompressor io.ReadCloser
digest hash.Hash32
err error
scratch [4]byte
}

Functions

Close method #

Close closes the Writer, flushing any unwritten data to the underlying io.Writer, but does not close the underlying io.Writer.

func (z *Writer) Close() error

Close method #

Calling Close does not close the wrapped [io.Reader] originally passed to [NewReader]. In order for the ZLIB checksum to be verified, the reader must be fully consumed until the [io.EOF].

func (z *reader) Close() error

Flush method #

Flush flushes the Writer to its underlying io.Writer.

func (z *Writer) Flush() error

NewReader function #

NewReader creates a new ReadCloser. Reads from the returned ReadCloser read and decompress data from r. If r does not 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 done. The [io.ReadCloser] returned by NewReader also implements [Resetter].

func NewReader(r io.Reader) (io.ReadCloser, error)

NewReaderDict function #

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].

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

NewWriter function #

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 NewWriter(w io.Writer) *Writer

NewWriterLevel function #

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 NewWriterLevel(w io.Writer, level int) (*Writer, error)

NewWriterLevelDict function #

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 NewWriterLevelDict(w io.Writer, level int, dict []byte) (*Writer, error)

Read method #

func (z *reader) Read(p []byte) (int, error)

Reset method #

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 (z *Writer) Reset(w io.Writer)

Reset method #

func (z *reader) Reset(r io.Reader, dict []byte) error

Write method #

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.

func (z *Writer) Write(p []byte) (n int, err error)

writeHeader method #

writeHeader writes the ZLIB header.

func (z *Writer) writeHeader() (err error)

Generated with Arrow