compress

package
v0.0.0-...-9bd9f91 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ready

func Ready() bool

Ready checks if the hardware is usable.

Types

type BufWriter

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

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

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

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

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.

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

type Gzip struct {
	Header
	UTF8 bool // can be used with gzip command
	// contains filtered or unexported fields
}

Gzip is an object to hold the state for compress data using gzip format.

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 = gzip.Header

Header is same as gzip.Header

type Inflate

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

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.

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

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

type Option func(opt *option)

Option type is used to configure how the library handles your compression or decompression.

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.

Directories

Path Synopsis
internal
codelencode
Package codelencode provides a function to prepare the code len code.
Package codelencode provides a function to prepare the code len code.
codelencode/avx2
Package avx2 provides avx2 version PrepareForCodeLenCode
Package avx2 provides avx2 version PrepareForCodeLenCode
codelencode/avx512
Package avx512 provides avx512 version PrepareForCodeLenCode
Package avx512 provides avx512 version PrepareForCodeLenCode
codelencode/sse2
Package sse2 provides sse2 version PrepareForCodeLenCode
Package sse2 provides sse2 version PrepareForCodeLenCode
huffman
Package huffman provices some implementations of different algorithms for generating Huffman trees.
Package huffman provices some implementations of different algorithms for generating Huffman trees.

Jump to

Keyboard shortcuts

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