Documentation ¶
Overview ¶
Package gzip provides a writer that embeds the standard library gzip.Writer and propagates calls to Flush and Close.
Package gzip provides a reader and writer that propagate calls to Flush and Close.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReadResetCloser ¶
func ReadBytes ¶
func ReadBytes(b []byte, multistream bool) (ReadResetCloser, error)
ReadBytes returns a reader for reading zlib-compressed bytes from an input slice. b is the input slice of compressed bytes. multistream toggles support for a sequence of multiple compressed files with their own header and trailer. In most cases, multistream should be true, as it is the standard behavior for a gzip reader.
type Reader ¶
func NewReader ¶
func NewReader(r io.ReadCloser) (*Reader, error)
NewReader creates a new Reader reading the given reader. If r does not also implement io.ByteReader, the decompressor may read more data than necessary from r.
It is the caller's responsibility to call Close on the Reader when done.
The Reader.Header fields will be valid in the Reader returned.
func (*Reader) Close ¶
Close closes the Reader. In order for the GZIP checksum to be verified, the reader must be fully consumed until the io.EOF Calls the Close method of the underlying reader, if it implements io.Closer.
func (*Reader) Multistream ¶
Multistream controls whether the reader supports multistream files.
If enabled (the default), the Reader expects the input to be a sequence of individually gzipped data streams, each with its own header and trailer, ending at EOF. The effect is that the concatenation of a sequence of gzipped files is treated as equivalent to the gzip of the concatenation of the sequence. This is standard behavior for gzip readers.
Calling Multistream(false) disables this behavior; disabling the behavior can be useful when reading file formats that distinguish individual gzip data streams or mix gzip data streams with other data streams. In this mode, when the Reader reaches the end of the data stream, Read returns io.EOF. The underlying reader must implement io.ByteReader in order to be left positioned just after the gzip stream. To start the next stream, call z.Reset(r) followed by z.Multistream(false). If there is no next stream, z.Reset(r) will return io.EOF.
type Writer ¶
func NewWriter ¶
NewWriter returns 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.
Callers that wish to set the fields in Writer.Header must do so before the first call to Write, Flush, or Close.
func NewWriterLevel ¶
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 (*Writer) Close ¶
Close closes the Writer by flushing any unwritten data to the underlying io.Writer and writing the GZIP footer. Calls the "Close() error" method of the underlying writer, if it implements io.Closer.
func (*Writer) Flush ¶
Flush flushes any pending compressed data to the underlying writer.
It is useful mainly in compressed network protocols, to ensure that a remote reader has enough data to reconstruct a packet. Flush does not return until the data has been written. If the underlying writer returns an error, Flush returns that error.
In the terminology of the zlib library, Flush is equivalent to Z_SYNC_FLUSH.