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

package libdeflate

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

Index

Package Files

libdeflate.go libdeflate_cgo.go

Constants

const (
    BestSpeed          = gzip.BestSpeed
    BestCompression    = gzip.BestCompression
    BestestCompression = 12
    DefaultCompression = gzip.DefaultCompression

    DefaultBufCap = 0x10000
)

These constants are copied from klauspost/compress/gzip. The BestCompression value is technically a lie for libdeflate--it goes all the way up to 12, not 9--so I've defined an extra constant for the real highest setting.

type Compressor Uses

type Compressor struct {
    // contains filtered or unexported fields
}

Compressor is a minimal interface to libdeflate's compressor object.

func (*Compressor) Cleanup Uses

func (cc *Compressor) Cleanup()

Cleanup frees workspace memory.

func (*Compressor) Compress Uses

func (cc *Compressor) Compress(outData, inData []byte) int

Compress performs raw DEFLATE compression on a byte slice. outData[] must be large enough to fit the compressed data. Byte count of the compressed data is returned on success. Zero is currently returned on failure. A side effect is that inData cannot be length zero; this function will panic or crash if it is.

func (*Compressor) Init Uses

func (cc *Compressor) Init(compressionLevel int) error

Init allocates workspace needed by Compress().

type Decompressor Uses

type Decompressor struct {
    // contains filtered or unexported fields
}

Decompressor is a minimal interface to libdeflate's decompressor object. It allocates a C memory area, so users are responsible for calling Decompressor.Cleanup() when done to avoid memory leaks. Multiple Decompressors can be active at once.

The Reader interface is not directly implemented here; instead, it is assumed that the user is decompressing a multi-block BGZF-like format, and they're fine with manual calls to Decompress().

func (*Decompressor) Cleanup Uses

func (dd *Decompressor) Cleanup()

Cleanup frees workspace memory.

func (*Decompressor) Decompress Uses

func (dd *Decompressor) Decompress(outData, inData []byte) (int, error)

Decompress performs raw DEFLATE decompression on a byte slice. outData[] must be large enough to fit the decompressed data. Byte count of the decompressed data is returned on success (it may be smaller than len(outData)).

func (*Decompressor) GzipDecompress Uses

func (dd *Decompressor) GzipDecompress(outData, inData []byte) (int, error)

GzipDecompress performs gzip decompression on a byte slice. outData[] must be large enough to fit the decompressed data. Byte count of the decompressed data is returned on success (it may be smaller than len(outData)).

func (*Decompressor) Init Uses

func (dd *Decompressor) Init() error

Init allocates workspace needed by Decompress().

type Writer Uses

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

A Writer is an io.WriteCloser. Writes to a Writer are compressed and written to w.

func NewWriter Uses

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

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, or any integer value between 1 and BestCompression inclusive. The error returned will be nil if the level is valid.

func (*Writer) Close Uses

func (z *Writer) Close() error

Close closes the Writer, flushing any unwritten data to the underlying io.Writer, but does not close the underlying io.Writer.

func (*Writer) Reset Uses

func (z *Writer) Reset(w 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.

It is safe to call Reset() without Close(). In this case, *no* bytes from the previous block are written.

func (*Writer) SetCap Uses

func (z *Writer) SetCap(newCap int) error

SetCap changes the capacity of the final write buffer, which must fit the entire gzip block (header and footer bytes included). (libdeflate requires this value to be declared in advance.) If this function isn't called, the capacity is set to DefaultBufCap == 0x10000.

func (*Writer) Write Uses

func (z *Writer) Write(p []byte) (int, error)

Write writes a compressed form of p to the underlying io.Writer. The compressed bytes are not necessarily flushed until the Writer is closed.

Package libdeflate imports 9 packages (graph) and is imported by 2 packages. Updated 2019-08-21. Refresh now. Tools for package owners.