compress

package
v0.0.0-...-44c758a Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, path string, opts ...file.Opts) (io.WriteCloser, bool)

Create creates path with file.Create and compresses with NewWriterPath.

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.

func Open

func Open(ctx context.Context, path string) (io.ReadCloser, bool)

Open opens path with file.Open and decompresses with NewReaderPath.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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