Documentation ¶
Overview ¶
Package lz4 implements compression using lz4.c and lz4hc.c
Copyright (c) 2016 Datadog Copyright (c) 2013 CloudFlare, Inc.
Index ¶
- Constants
- func Compress(out, in []byte) (outSize int, err error)
- func CompressAllocHdr(in []byte) (out []byte, err error)
- func CompressBound(in []byte) int
- func CompressBoundHdr(in []byte) int
- func CompressBoundInt(inputSize int) int
- func CompressHC(out, in []byte) (int, error)
- func CompressHCHdr(out, in []byte) (count int, err error)
- func CompressHCLevel(out, in []byte, level int) (outSize int, err error)
- func CompressHCLevelHdr(out, in []byte, level int) (count int, err error)
- func CompressHdr(out, in []byte) (count int, err error)
- func NewReader(r io.Reader) io.ReadCloser
- func Uncompress(out, in []byte) (outSize int, err error)
- func UncompressAllocHdr(out, in []byte) ([]byte, error)
- func UncompressHdr(out, in []byte) error
- type Writer
Constants ¶
const ( // MaxInputSize is the max supported input size. see macro LZ4_MAX_INPUT_SIZE. MaxInputSize = 0x7E000000 // 2 113 929 216 bytes )
Variables ¶
This section is empty.
Functions ¶
func Compress ¶
Compress compresses in and puts the content in out. len(out) should have enough space for the compressed data (use CompressBound to calculate). Returns the number of bytes in the out slice.
func CompressAllocHdr ¶
CompressAllocHdr is like Compress, but allocates the out slice itself and automatically resizes it to the proper size of the compressed output. This can be more convenient to use if you are in a situation where you cannot reuse buffers.
func CompressBound ¶
CompressBound calculates the size of the output buffer needed by Compress. This is based on the following macro:
#define LZ4_COMPRESSBOUND(isize)
((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
func CompressBoundHdr ¶
CompressBoundHdr returns the upper bounds of the size of the compressed byte plus space for a length header.
func CompressBoundInt ¶
CompressBoundInt returns the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible). see macro LZ4_COMPRESSBOUND.
func CompressHC ¶
CompressHC compresses in and puts the content in out. len(out) should have enough space for the compressed data (use CompressBound to calculate). Returns the number of bytes in the out slice. Determines the compression level automatically.
func CompressHCHdr ¶
CompressHCHdr implements high-compression ratio compression.
func CompressHCLevel ¶
CompressHCLevel compresses in at the given compression level and puts the content in out. len(out) should have enough space for the compressed data (use CompressBound to calculate). Returns the number of bytes in the out slice. To automatically choose the compression level, use 0. Otherwise, use any value in the inclusive range 1 (worst) through 16 (best). Most applications will prefer CompressHC.
func CompressHCLevelHdr ¶
CompressHCLevelHdr implements high-compression ratio compression.
func CompressHdr ¶
CompressHdr compresses in to out. It returns the number of bytes written to out and any errors that may have been encountered. This version adds a 4-byte little endian "header" indicating the length of the original message so that it may be decompressed successfully later.
func NewReader ¶
func NewReader(r io.Reader) io.ReadCloser
NewReader creates a new io.ReadCloser. Reads from the returned ReadCloser read and decompress data from r. It is the caller's responsibility to call Close on the ReadCloser when done. If this is not done, underlying objects in the lz4 library will not be freed.
func Uncompress ¶
Uncompress with a known output size. len(out) should be equal to the length of the uncompressed out.
func UncompressAllocHdr ¶
UncompressAllocHdr uncompresses the stream from in into out if out has enough space. Otherwise, a new slice is allocated automatically and returned. This function uses the "length header" to detemrine how much space is necessary fo the result message, which CloudFlare's implementation doesn't have.
func UncompressHdr ¶
UncompressHdr uncompresses in into out. Out must have enough space allocated for the uncompressed message.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is an io.WriteCloser that lz4 compress its input.
func NewWriter ¶
NewWriter creates a new Writer. Writes to the writer will be written in compressed form to w.