gzip

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

type ReadResetCloser interface {
	io.Reader
	io.Closer
	Resetter
}

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

type Reader struct {
	Header gzip.Header
	// contains filtered or unexported fields
}

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 ReadFile

func ReadFile(path string, bufferSize int) (*Reader, error)

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

func (*Reader) Close

func (r *Reader) Close() error

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

func (r *Reader) Multistream(ok bool)

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.

func (*Reader) Read

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

Read implements io.Reader, reading uncompressed bytes from its underlying Reader.

func (*Reader) Reset

func (r *Reader) Reset(reader io.ReadCloser) error

Reset discards the Reader z's state and makes it equivalent to the result of its original state from NewReader, but reading from r instead. This permits reusing a Reader rather than allocating a new one.

type Resetter

type Resetter interface {
	Reset(r io.Reader) error
}

type Writer

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

func NewWriter

func NewWriter(w io.Writer) *Writer

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

func NewWriterLevel(w io.Writer, 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 WriteFile

func WriteFile(path string, 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 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

func (w *Writer) Flush() error

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.

func (*Writer) Reset

func (w *Writer) Reset(writer io.Writer)

Reset discards the Writer z's state and makes it equivalent to the result of its original state from NewWriter or NewWriterLevel, but writing to w instead. This permits reusing a Writer rather than allocating a new one.

Jump to

Keyboard shortcuts

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