base: github.com/grailbio/base/compress Index | Files | Directories

package compress

import "github.com/grailbio/base/compress"

Package compress provides convenience functions for creating compressors and uncompressors based on filenames.

Index

Package Files

rw.go

func NewReader Uses

func NewReader(r io.Reader) (io.ReadCloser, bool)

NewReader creates an uncompressing reader by reading the first few bytes of the input and finding a magic header for either gzip, zstd, bzip2. If the magic header is found , it returns an uncompressing ReadCloser and true. Else, it returns ioutil.NopCloser(r) and false.

CAUTION: this function will misbehave when the input is a binary string that happens to have the same magic gzip, zstd, or bzip2 header. Thus, you should use this function only when the input is expected to be ASCII.

func NewReaderPath Uses

func NewReaderPath(r io.Reader, path string) (io.ReadCloser, bool)

NewReaderPath creates a reader that uncompresses data read from the given reader. The compression format is determined by the pathname extensions. If the pathname ends with one of the following extensions, it creates an uncompressing ReadCloser and returns true.

.gz => gzip format
.zst => zstd format
.bz2 => bz2 format

For other extensions, this function returns an ioutil.NopCloser(r) and false.

The caller must close the ReadCloser after use. For some file formats, Close() is the only place that reports file corruption.

func NewWriterPath Uses

func NewWriterPath(w io.Writer, path string) (io.WriteCloser, bool)

NewWriterPath creates a WriteCloser that compresses data. The compression format is determined by the pathname extensions. If the pathname ends with one of the following extensions, it creates an compressing WriteCloser and returns true.

.gz => gzip format
.zst => zstd format

For other extensions, this function creates a noop WriteCloser and returns false. The caller must close the WriteCloser after use.

Directories

PathSynopsis
libdeflate
zstd

Package compress imports 10 packages (graph) and is imported by 2 packages. Updated 2019-09-20. Refresh now. Tools for package owners.