zlibng

package module
v0.0.0-...-2a86006 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2019 License: Zlib Imports: 8 Imported by: 4

README

GoDoc

Cgo wrapper for zlib-ng (https://github.com/zlib-ng/zlib-ng). It currently supports only {linux,darwin}/amd64.

  • The reader implements io.ReadCloser, the writer implements io.WriteCloser.

  • Supports both gzip and flate formats.

  • Supports multi-part archive (concatenated gzip/flate file).

  • Supports reading and writing the gzip header.

Benchmark results:

CPU: Intel(R) Xeon(R) CPU E3-1505M v6 @ 3.00GHz

goos: linux
goarch: amd64
pkg: github.com/yasushi-saito/zlibng
BenchmarkInflateStandardGzip-8    	     100	  16481110 ns/op
BenchmarkInflateKlauspostGzip-8   	     100	  19946956 ns/op
BenchmarkInflateZlibNG-8          	     200	   5908574 ns/op
BenchmarkInflateCGZip-8           	     200	   7771587 ns/op
BenchmarkDeflateStandardGzip-8    	       1	10572484457 ns/op
BenchmarkDeflateKlauspostGzip-8   	       1	2665946548 ns/op
BenchmarkDeflateZlibNG-8          	       1	5886680851 ns/op
BenchmarkDeflateCGZip-8           	       1	5069861793 ns/op

Installation

go get github.com/yasushi-saito/zlibng

Incorporating upstream changes

cd /tmp/
git clone https://github.com/zlib-ng/zlib-ng.git
git clone git@github.com:yasushi-saito/zlibng.git
cd zlibng
./patch.py ../zlib-ng
git commit -a

Documentation

Index

Constants

View Source
const (
	// FilteredStrategy stands for C.Z_FILTERED
	FilteredStrategy = 1
	// HuffmanOnlyStrategy stands for  C.Z_HUFFMAN_ONLY
	HuffmanOnlyStrategy = 2
	// RLEStrategy stands for C.Z_RLE
	RLEStrategy = 3
	// FixedStrategy stands for C.Z_FIXED
	FixedStrategy = 4
	// DefaultStrategy stands for C.Z_DEFAULT_STRATEGY
	DefaultStrategy = 0
)

Strategy values

View Source
const (
	// Gzip is the value of Opts.WindowBits to use FLATE format as defined in RFC1952
	Gzip = 16 + 15
	// Flate should is the value of Opts.WindowBits to use FLATE format as defined in RFC1951
	Flate = -15
)
View Source
const DefaultBufferSize = 512 * 1024

DefaultBufferSize is the default value of Opts.Buffer

Variables

This section is empty.

Functions

This section is empty.

Types

type GzipHeader

type GzipHeader struct {
	Comment string
	Extra   []byte
	ModTime time.Time
	Name    string
	// OS field, cf. RFC1952 Section 2.3. Default: 255
	OS byte
}

GzipHeader alters the contents the gzip header. It is stored in Opts.GzipHeader to control the contents of the header.

TODO(saito) Support other fields if needed.

type Opts

type Opts struct {
	// WindowBits specifies the windowBits arg for deflateInit and inflateInit. It
	// specifies the compression window size as well as the header format.  If
	// unset, Gzip is used.
	WindowBits int
	// Buffer specifies the internal buffer size used during compression and
	// decompression.  The default value is 512KiB.
	Buffer int
	// Level specifies the compression level, used only by the writer.
	// The default value of 0 means no compression, which is probably not what you want.
	// -1 is the default compression level. If you don't pass any Opts to NewWriter,
	// it will use -1 as the value.
	Level int

	// MemLevel specifies the memLevel arg for deflateInit2. If unset, value of 8
	// is used.
	MemLevel int
	// Strategy specifies the strategy arg for deflateInit. If unset,
	// Z_DEFAULT_STRATEGY is used.
	Strategy int
}

Opts define the options passed to NewReader and NewWriter.

type Reader

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

Reader is a gzip/zlib/flate reader. It implements io.ReadCloser. Calling Close is optional, though strongly recommended. NewReader() also installs a GC finalizer that closes the Reader, in case the application forgets to call Close.

func NewReader

func NewReader(in io.Reader, opts ...Opts) (*Reader, error)

NewReader creates a gzip/flate reader. There can be at most one options arg.

func (*Reader) Close

func (z *Reader) Close() error

Close implements io.Closer.

func (*Reader) Header

func (z *Reader) Header() (GzipHeader, error)

Header reads the gzip header contents. If the file is a multi-gzip concatenation, this function returns the contents of the current archive.

REQUIRES: Opts.GetGzipHeader=true when the reader was created.

func (*Reader) Read

func (z *Reader) Read(out []byte) (int, error)

Read implements io.Reader.

type Writer

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

Writer is the gzip/flate writer. It implements io.WriterCloser.

func NewWriter

func NewWriter(w io.Writer, opts ...Opts) (*Writer, error)

NewWriter creates a gzip/flate writer. There can be at most one options arg. If opts is empty, NewWriter will use Opts{Format:Gzip,Level:-1}.

func (*Writer) Close

func (z *Writer) Close() error

Close implements io.Closer

func (*Writer) SetHeader

func (z *Writer) SetHeader(h GzipHeader) error

SetHeader sets the Gzip header contents.

REQUIRES: No Write nor Close has been called yet. REQUIRES: The archive format is Gzip.

func (*Writer) Write

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

Write implements io.Writer.

Jump to

Keyboard shortcuts

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