Documentation ¶
Index ¶
- Constants
- func Adler32(adler32 uint32, in []byte) uint32
- func CompressDEFLATE(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int
- func CompressGzip(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int
- func CompressZlib(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int
- func Crc32(crc32 uint32, in []byte) uint32
- func DecompressDEFLATE(dc *C.decomp, inAddr, outAddr *byte, inSize, outSize int, sPtr uintptr) error
- func DecompressGzip(dc *C.decomp, inAddr, outAddr *byte, inSize, outSize int, sPtr uintptr) error
- func DecompressZlib(dc *C.decomp, inAddr, outAddr *byte, inSize, outSize int, sPtr uintptr) error
- func DeflateBound(c *C.comp, s int) int
- func GzipBound(c *C.comp, s int) int
- func ZlibBound(c *C.comp, s int) int
- type Compressor
- type Decompressor
Constants ¶
const ( MinCompressionLevel = 1 MaxStdZlibCompressionLevel = 9 MaxCompressionLevel = 12 DefaultCompressionLevel = 6 )
Variables ¶
This section is empty.
Functions ¶
func Adler32 ¶ added in v1.3.1
Adler32 works as described in native/libs/libdeflate.h. Returns 1 for in == nil
func CompressDEFLATE ¶ added in v1.1.0
CompressDEFLATE interfaces with c libdeflate for DEFLATE compression
func CompressGzip ¶ added in v1.1.0
CompressGzip interfaces with c libdeflate for gzip compression
func CompressZlib ¶ added in v1.1.0
CompressZlib interfaces with c libdeflate for zlib compression
func Crc32 ¶ added in v1.3.1
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
DecompressGzip interfaces with c libdeflate for gzip decompression
func DecompressZlib ¶ added in v1.1.0
DecompressZlib interfaces with c libdeflate for zlib decompression
func DeflateBound ¶ added in v1.3.1
DeflateBound 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.