gzip

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 6 Imported by: 0

Documentation

Overview

The gzip package implements reading and writing of gzip format compressed files, as specified in RFC 1952.

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/gzip" does not also have to import "compress/flate".

Variables

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

Functions

This section is empty.

Types

type Deflater

type Deflater struct {
	Header
	// contains filtered or unexported fields
}

A Deflater is an io.WriteCloser that satisfies writes by compressing data written to its wrapped io.Writer.

func NewDeflater

func NewDeflater(w io.Writer) (*Deflater, os.Error)

NewDeflater calls NewDeflaterLevel with the default compression level.

func NewDeflaterLevel

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

NewDeflaterLevel creates a new Deflater writing to the given writer. Writes may be buffered and not flushed until Close. Callers that wish to set the fields in Deflater.Header must do so before the first call to Write or Close. 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).

func (*Deflater) Close

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

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

func (*Deflater) Write

func (z *Deflater) Write(p []byte) (int, os.Error)
type Header struct {
	Comment string // comment
	Extra   []byte // "extra data"
	Mtime   uint32 // modification time (seconds since January 1, 1970)
	Name    string // file name
	OS      byte   // operating system type
}

The gzip file stores a header giving metadata about the compressed file. That header is exposed as the fields of the Deflater and Inflater structs.

type Inflater

type Inflater struct {
	Header
	// contains filtered or unexported fields
}

An Inflater is an io.Reader that can be read to retrieve uncompressed data from a gzip-format compressed file.

In general, a gzip file can be a concatenation of gzip files, each with its own header. Reads from the Inflater return the concatenation of the uncompressed data of each. Only the first header is recorded in the Inflater fields.

Gzip files store a length and checksum of the uncompressed data. The Inflater will return a ChecksumError when Read reaches the end of the uncompressed data if it does not have the expected length or checksum. Clients should treat data returned by Read as tentative until they receive the successful (zero length, nil error) Read marking the end of the data.

func NewInflater

func NewInflater(r io.Reader) (*Inflater, os.Error)

NewInflater creates a new Inflater 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 Inflater when done.

func (*Inflater) Close

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

Calling Close does not close the wrapped io.Reader originally passed to NewInflater.

func (*Inflater) Read

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

Notes

Bugs

  • Comments and Names don't properly map UTF-8 character codes outside of the 0x00-0x7f range to ISO 8859-1 (Latin-1).

Jump to

Keyboard shortcuts

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