zlib

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 zlib provides a writer that embeds the standard library zlib.Writer and propagates calls to Flush and Close.

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

Index

Constants

View Source
const (
	NoCompression      = zlib.NoCompression
	BestSpeed          = zlib.BestSpeed
	BestCompression    = zlib.BestCompression
	DefaultCompression = zlib.DefaultCompression
	HuffmanOnly        = zlib.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, error)

ReadBytes returns a reader for reading zlib-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, error)

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 ReadCloser returned by NewReader also implements Resetter.

func NewReaderDict

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

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 ReadFile

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

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

func (*Reader) Close

func (r *Reader) Close() error

Close closes the Reader and the underlying io.ReadCloser.

func (*Reader) Read

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

Read implements the io.Reader inferface.

func (*Reader) Reset

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

Reset 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

type Resetter interface {
	Reset(r io.Reader, dict []byte) error
}

type Writer

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

func NewWriter

func NewWriter(w io.WriteCloser) *Writer

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 NewWriterDict

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

NewWriterDict is like NewWriter 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 NewWriterLevel

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

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

func NewWriterLevelDict(w io.WriteCloser, 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 WriteFile

func WriteFile(path string, dict []byte, 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 zlib writer, and then flushes and closes the underlying writer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes any pending data to the underlying writer. Then calls the Flush method of the underlying writer, if it implements it.

Jump to

Keyboard shortcuts

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