import "github.com/intel/ixl-go/compress"
Package compress provides hardware compression ability (IAA).
Example
package main
import (
"bytes"
"crypto/rand"
"io"
"log"
"github.com/intel/ixl-go/compress"
)
func main() {
input := make([]byte, 1024)
_, _ = rand.Read(input)
var w io.WriteCloser
d, err := compress.NewDeflate(bytes.NewBuffer(nil))
if err != nil {
// IAA devices not found
log.Fatalln(err)
}
w = compress.NewWriter(d)
_, _ = w.Write(input)
_ = w.Close()
}
- func Ready() bool
- type BufWriter
- func NewDeflateWriter(w io.Writer, opts ...Option) (*BufWriter, error)
- func NewGzipWriter(w io.Writer, opts ...Option) *BufWriter
- func NewWriter(bw blockWriter) *BufWriter
- func (w *BufWriter) Close() error
- func (w *BufWriter) Flush() error
- func (w *BufWriter) Reset(writer io.Writer)
- func (w *BufWriter) Write(data []byte) (n int, err error)
- type Deflate
- type Gzip
- type Header
- type Inflate
- func NewInflate(r io.Reader, opts ...Option) (*Inflate, error)
- func NewInflateWithBufferSize(r io.Reader, bufferSize int, opts ...Option) (*Inflate, error)
- func (i *Inflate) DecompressAll(compressed []byte, raw []byte) (int, error)
- func (i *Inflate) Read(data []byte) (n int, err error)
- func (i *Inflate) Reset(r io.Reader)
- type Option
func Ready
func Ready() bool
Ready checks if the hardware is usable.
type BufWriter
BufWriter is a buffer writer for wrapping Deflate/Gzip as a io.Writer.
type BufWriter struct {
// contains filtered or unexported fields
}
func NewDeflateWriter
func NewDeflateWriter(w io.Writer, opts ...Option) (*BufWriter, error)
NewDeflateWriter create a deflate writer
func NewGzipWriter
func NewGzipWriter(w io.Writer, opts ...Option) *BufWriter
NewGzipWriter create a gzip writer
func NewWriter
func NewWriter(bw blockWriter) *BufWriter
NewWriter create a new BufWriter. The argument should be Gzip or Deflate.
func (*BufWriter) Close
func (w *BufWriter) Close() error
Close flush all buffered data to underlying block writer and close it.
func (*BufWriter) Flush
func (w *BufWriter) Flush() error
Flush immediately write all buffered data to underlying block writer.
func (*BufWriter) Reset
func (w *BufWriter) Reset(writer io.Writer)
Reset writer.
func (*BufWriter) Write
func (w *BufWriter) Write(data []byte) (n int, err error)
Write data to underlying block writer.
type Deflate
Deflate takes data written to it and writes the deflate compressed form of that data to an underlying writer (see NewDeflate).
Notice:
- the history buffer used by hardware is 4KB.
- the `Deflate` object should be reused as much as possible to reduce the GC overhead.
type Deflate struct {
// contains filtered or unexported fields
}
func NewDeflate
func NewDeflate(w io.Writer, opts ...Option) (*Deflate, error)
NewDeflate returns a new Deflate writing compressed data to underlying writer `w`.
func (*Deflate) Close
func (d *Deflate) Close() error
Close the underlying writer.
func (*Deflate) ReadFrom
func (d *Deflate) ReadFrom(r io.Reader) (total int64, err error)
ReadFrom reads all data from `r` and compresses the data and then writes compressed data into underlying writer `w`.
func (*Deflate) Reset
func (d *Deflate) Reset(w io.Writer)
Reset the `Deflate` object.
type Gzip
Gzip is an object to hold the state for compress data using gzip format.
type Gzip struct {
Header
UTF8 bool // can be used with gzip command
// contains filtered or unexported fields
}
func NewGzip
func NewGzip(w io.Writer, opts ...Option) *Gzip
NewGzip create a new Gzip.
func (*Gzip) Close
func (g *Gzip) Close() error
Close the writer.
func (*Gzip) ReadFrom
func (g *Gzip) ReadFrom(reader io.Reader) (n int64, err error)
ReadFrom reads all data from `r` and compresses the data and then writes compressed data into underlying writer `w`.
func (*Gzip) Reset
func (g *Gzip) Reset(w io.Writer)
Reset the internal states for reusing the object.
type Header
Header is same as gzip.Header
type Header = gzip.Header
type Inflate
Inflate reads data from reader r and decompresses them.
Notice: the compressed data must be compressed by IAA or the whole stream must not larger than 4KB. This because the standard deflate's history buffer size is 32KB, but the IAA deflate's history buffer size is 4KB.
type Inflate struct {
// contains filtered or unexported fields
}
func NewInflate
func NewInflate(r io.Reader, opts ...Option) (*Inflate, error)
NewInflate creates a new Inflate with 4KB buffer size to decompress data from reader r.
func NewInflateWithBufferSize(r io.Reader, bufferSize int, opts ...Option) (*Inflate, error)
NewInflateWithBufferSize creates a new Inflate with specified buffer size to decompress data from reader r.
func (*Inflate) DecompressAll
func (i *Inflate) DecompressAll(compressed []byte, raw []byte) (int, error)
DecompressAll decompress all compressed data and write result into raw. The caller should make sure that `raw` has enough space.
func (*Inflate) Read
func (i *Inflate) Read(data []byte) (n int, err error)
Read decompressed data from the underlying compressed reader.
func (*Inflate) Reset
func (i *Inflate) Reset(r io.Reader)
Reset reset the Inflate object
type Option
Option type is used to configure how the library handles your compression or decompression.
type Option func(opt *option)
func BusyPoll
func BusyPoll() Option
BusyPoll enable busy-poll mode to reduce the deflate latency. Beware it may cause more CPU cost.
func DynamicMode
func DynamicMode() Option
DynamicMode enable dynamic mode to compress the data.
func FixedMode
func FixedMode() Option
FixedMode enable fixed mode to compress the data.
func HuffmanOnly
func HuffmanOnly() Option
HuffmanOnly enable huffman code only mode to compress the data.
Generated by gomarkdoc