README

This is a simple Go wrapper for libdeflate.

Documentation

Index

Constants

View Source
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.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Compressor

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

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

      func (*Compressor) Cleanup

      func (cc *Compressor) Cleanup()

        Cleanup frees workspace memory.

        func (*Compressor) Compress

        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

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

            Init allocates workspace needed by Compress().

            type Decompressor

            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

              func (dd *Decompressor) Cleanup()

                Cleanup frees workspace memory.

                func (*Decompressor) Decompress

                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

                  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

                    func (dd *Decompressor) Init() error

                      Init allocates workspace needed by Decompress().

                      type Writer

                      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

                        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

                          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

                            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

                              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

                                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

                                  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.