Back to godoc.org

Package compress

v0.0.9
Latest Go to latest

The latest major version is .

Published: Jun 24, 2020 | License: Apache-2.0 | Module: github.com/grailbio/base

Overview

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

Index

func NewReader

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

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

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.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier