native

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MinCompressionLevel        = 1
	MaxStdZlibCompressionLevel = 9
	MaxCompressionLevel        = 12
	DefaultCompressionLevel    = 6
)

Variables

This section is empty.

Functions

func Adler32 added in v1.3.1

func Adler32(adler32 uint32, in []byte) uint32

Adler32 works as described in native/libs/libdeflate.h. Returns 1 for in == nil

func CompressDEFLATE added in v1.1.0

func CompressDEFLATE(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int

CompressDEFLATE interfaces with c libdeflate for DEFLATE compression

func CompressGzip added in v1.1.0

func CompressGzip(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int

CompressGzip interfaces with c libdeflate for gzip compression

func CompressZlib added in v1.1.0

func CompressZlib(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int

CompressZlib interfaces with c libdeflate for zlib compression

func Crc32 added in v1.3.1

func Crc32(crc32 uint32, in []byte) uint32

Crc32 works as described in native/libs/libdeflate.h. Returns 0 for in == nil

func DecompressDEFLATE added in v1.1.0

func DecompressDEFLATE(dc *C.decomp, inAddr, outAddr *byte, inSize, outSize int, sPtr uintptr) error

DecompressDEFLATE interfaces with c libdeflate for DEFLATE decompression

func DecompressGzip added in v1.1.0

func DecompressGzip(dc *C.decomp, inAddr, outAddr *byte, inSize, outSize int, sPtr uintptr) error

DecompressGzip interfaces with c libdeflate for gzip decompression

func DecompressZlib added in v1.1.0

func DecompressZlib(dc *C.decomp, inAddr, outAddr *byte, inSize, outSize int, sPtr uintptr) error

DecompressZlib interfaces with c libdeflate for zlib decompression

func DeflateBound added in v1.3.1

func DeflateBound(c *C.comp, s int) int

DeflateBound works as described in native/libs/libdeflate.h

func GzipBound added in v1.3.1

func GzipBound(c *C.comp, s int) int

GzipBound works as described in native/libs/libdeflate.h

func ZlibBound added in v1.3.1

func ZlibBound(c *C.comp, s int) int

ZlibBound works as described in native/libs/libdeflate.h

Types

type Compressor

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

Compressor compresses data to zlib format at the specified level

func NewCompressor

func NewCompressor(lvl int) (*Compressor, error)

NewCompressor returns a new Compressor used to compress data. Errors if out of memory or invalid lvl

func (*Compressor) Close

func (c *Compressor) Close()

Close frees the memory allocated by C objects

func (*Compressor) Compress

func (c *Compressor) Compress(in, out []byte, f compress) (int, []byte, error)

Compress compresses the data from in to out and returns the number of bytes written to out, out and an error if the out buffer was too short. If you pass nil for out, this function will allocate a fitting buffer and return it.

Notice that for extremely small or already highly compressed data, the compressed data could be larger than uncompressed. If out == nil: For a too large discrepancy (len(out) > 1000 + 2 * len(in)) Compress will error

func (*Compressor) UpperBound added in v1.3.1

func (c *Compressor) UpperBound(size int, f bound) int

UpperBound works as described in native/libs/libdeflate.h

type Decompressor

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

Decompressor decompresses any DEFLATE, zlib or gzip compressed data at any level

func NewDecompressor

func NewDecompressor() (*Decompressor, error)

NewDecompressor returns a new Decompressor with maxDecompressionFactor = 30 or and error if out of memory

func NewDecompressorWithExtendedDecompression added in v1.3.2

func NewDecompressorWithExtendedDecompression(maxDecompressionFactor int) (*Decompressor, error)

NewDecompressorWithExtendedDecompression returns a new Decompressor with maxDecompressionFactor or and error if out of memory

func (*Decompressor) Close

func (dc *Decompressor) Close()

Close frees the memory allocated by C objects

func (*Decompressor) Decompress

func (dc *Decompressor) Decompress(in, out []byte, f decompress) ([]byte, error)

Decompress decompresses the given data from in to out and returns out and an error if something went wrong. If error != nil, then the data in out is undefined. If you pass a buffer to out, the size of this buffer must exactly match the length of the decompressed data. If you pass nil as out, this function will allocate a sufficient buffer and return it.

Jump to

Keyboard shortcuts

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