Documentation ¶
Overview ¶
Package lz4 implements compression using lz4.c and lz4hc.c
Copyright (c) 2016 Datadog Copyright (c) 2013 CloudFlare, Inc.
Index ¶
- 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 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 NewDecompressReader(r io.Reader) io.ReadCloser
- func NewReader(r io.Reader) io.ReadCloserdeprecated
- func Uncompress(out, in []byte) (outSize int, err error)
- func UncompressAllocHdr(out, in []byte) ([]byte, error)
- func UncompressHdr(out, in []byte) error
- type CompressReader
- type DecompressReader
- type Writer
Constants ¶
This section is empty.
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 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 NewDecompressReader ¶ added in v1.1.0
func NewDecompressReader(r io.Reader) io.ReadCloser
NewDecompressReader creates a new io.ReadCloser. This function mirrors the behavior of NewReader but provides better performance. 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 NewReader
deprecated
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.
Deprecated: Use NewDecompressReader instead. It can decompress the output of NewWriter, but uses fewer allocations.
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 determine how much space is necessary for 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 CompressReader ¶ added in v1.1.0
type CompressReader struct {
// contains filtered or unexported fields
}
CompressReader reads input and creates an io.ReadCloser for reading compressed output
func NewCompressReader ¶ added in v1.1.0
func NewCompressReader(r io.Reader) *CompressReader
NewCompressReader creates a new io.ReadCloser. Reads from the returned ReadCloser read and compress 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. The compressed output must be decompressed using NewDecompressReader.
func (*CompressReader) Close ¶ added in v1.1.0
func (r *CompressReader) Close() error
Close releases all the resources occupied by Reader. r cannot be used after the release.
type DecompressReader ¶ added in v1.1.0
type DecompressReader struct {
// contains filtered or unexported fields
}
DecompressReader is an io.ReadCloser that decompresses when read from.
func (*DecompressReader) Close ¶ added in v1.1.0
func (r *DecompressReader) Close() error
Close releases all the resources occupied by r. r cannot be used after the release.
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.