zlib

package
v0.0.0-...-e758773 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2011 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package zlib implements reading and writing of zlib format compressed data, as specified in RFC 1950.

The implementation provides filters that uncompress during reading and compress during writing. For example, to write compressed data to a buffer:

var b bytes.Buffer
w, err := zlib.NewWriter(&b)
w.Write([]byte("hello, world\n"))
w.Close()

and to read that data back:

r, err := zlib.NewReader(&b)
io.Copy(os.Stdout, r)
r.Close()

Index

Constants

View Source
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".

Variables

View Source
var ChecksumError os.Error = os.ErrorString("zlib checksum error")
View Source
var DictionaryError os.Error = os.ErrorString("invalid zlib dictionary")
View Source
var HeaderError os.Error = os.ErrorString("invalid zlib header")

Functions

func NewReader

func NewReader(r io.Reader) (io.ReadCloser, os.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.

func NewReaderDict

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

NewReaderDict is like NewReader but uses a preset dictionary. NewReaderDict ignores the dictionary if the compressed data does not refer to it.

Types

type Writer

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

func NewWriter(w io.Writer) (*Writer, os.Error)

NewWriter calls NewWriterLevel with the default compression level.

func NewWriterDict

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

NewWriterDict creates a new io.WriteCloser that satisfies writes by compressing data written to w. It is the caller's responsibility to call Close on the WriteCloser when done. level is the compression level, which can be DefaultCompression, NoCompression, or any integer value between BestSpeed and BestCompression (inclusive). dict is the preset dictionary to compress with, or nil to use no dictionary.

func NewWriterLevel

func NewWriterLevel(w io.Writer, level int) (*Writer, os.Error)

NewWriterLevel calls NewWriterDict with no dictionary.

func (*Writer) Close

func (z *Writer) Close() os.Error

Calling Close does not close the wrapped io.Writer originally passed to NewWriter.

func (*Writer) Flush

func (z *Writer) Flush() os.Error

Flush flushes the underlying compressor.

func (*Writer) Write

func (z *Writer) Write(p []byte) (n int, err os.Error)

Jump to

Keyboard shortcuts

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