Skip to content

Latest commit

 

History

History
377 lines (266 loc) · 10.6 KB

doc.md

File metadata and controls

377 lines (266 loc) · 10.6 KB

compress

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()
}

Index

func Ready

func Ready() bool

Ready checks if the hardware is usable.

BufWriter is a buffer writer for wrapping Deflate/Gzip as a io.Writer.

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

func NewDeflateWriter(w io.Writer, opts ...Option) (*BufWriter, error)

NewDeflateWriter create a deflate writer

func NewGzipWriter(w io.Writer, opts ...Option) *BufWriter

NewGzipWriter create a gzip writer

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:

  1. the history buffer used by hardware is 4KB.
  2. 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(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(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() Option

BusyPoll enable busy-poll mode to reduce the deflate latency. Beware it may cause more CPU cost.

func DynamicMode() Option

DynamicMode enable dynamic mode to compress the data.

func FixedMode() Option

FixedMode enable fixed mode to compress the data.

func HuffmanOnly() Option

HuffmanOnly enable huffman code only mode to compress the data.

Generated by gomarkdoc