// Package lz4 implements reading and writing lz4 compressed data. // // The package supports both the LZ4 stream format, // as specified in http://fastcompression.blogspot.fr/2013/04/lz4-streaming-format-final.html, // and the LZ4 block format, defined at // http://fastcompression.blogspot.fr/2011/05/lz4-explained.html. // // See https://github.com/lz4/lz4 for the reference C implementation.
package lz4 import ( ) func _() { // Safety checks for duplicated elements. var [1]struct{} _ = [lz4block.CompressionLevel(Fast)-lz4block.Fast] _ = [lz4block.CompressionLevel(CCompatFast)-lz4block.CCompatFast] _ = [Block64Kb-BlockSize(lz4block.Block64Kb)] _ = [Block256Kb-BlockSize(lz4block.Block256Kb)] _ = [Block1Mb-BlockSize(lz4block.Block1Mb)] _ = [Block4Mb-BlockSize(lz4block.Block4Mb)] } // CompressBlockBound returns the maximum size of a given buffer of size n, when not compressible. func ( int) int { return lz4block.CompressBlockBound() } // UncompressBlock uncompresses the source buffer into the destination one, // and returns the uncompressed size. // // The destination buffer must be sized appropriately. // // An error is returned if the source data is invalid or the destination buffer is too small. func (, []byte) (int, error) { return lz4block.UncompressBlock(, , nil) } // UncompressBlockWithDict uncompresses the source buffer into the destination one using a // dictionary, and returns the uncompressed size. // // The destination buffer must be sized appropriately. // // An error is returned if the source data is invalid or the destination buffer is too small. func (, , []byte) (int, error) { return lz4block.UncompressBlock(, , ) } // A Compressor compresses data into the LZ4 block format. // It uses a fast compression algorithm. // // A Compressor is not safe for concurrent use by multiple goroutines. // // Use a Writer to compress into the LZ4 stream format. type Compressor struct{ c lz4block.Compressor } // CompressBlock compresses the source buffer src into the destination dst. // // If compression is successful, the first return value is the size of the // compressed data, which is always >0. // // If dst has length at least CompressBlockBound(len(src)), compression always // succeeds. Otherwise, the first return value is zero. The error return is // non-nil if the compressed data does not fit in dst, but it might fit in a // larger buffer that is still smaller than CompressBlockBound(len(src)). The // return value (0, nil) means the data is likely incompressible and a buffer // of length CompressBlockBound(len(src)) should be passed in. func ( *Compressor) (, []byte) (int, error) { return .c.CompressBlock(, ) } // CompressBlock is equivalent to Compressor.CompressBlock. // The final argument is ignored and should be set to nil. // // This function is deprecated. Use a Compressor instead. func (, []byte, []int) (int, error) { return lz4block.CompressBlock(, ) } // A CompressorCCompat compresses data into the LZ4 block format with the // reference implementation's fast algorithm, and produces the same output as // its LZ4_compress_fast. // // Compressor, which the default Fast level uses, is the better choice for most // data. CompressorCCompat is for output that must match the C implementation, // or for more throughput with blocks of 64kiB or more, where it is faster // than Compressor on most data but compresses text less. With smaller blocks, // or high-entropy input such as digits, it is slower than Compressor. // // A CompressorCCompat is not safe for concurrent use by multiple goroutines. // // Use a Writer with CompressionLevelOption(CCompatFast) to compress into the // LZ4 stream format. type CompressorCCompat struct { // Acceleration trades compression for speed, as in LZ4_compress_fast: // each increment skips more positions when no match is found. // Values below 1 mean the default of 1. Acceleration int c lz4block.CompressorCCompat } // CompressBlock compresses the source buffer src into the destination dst. // // If compression is successful, the first return value is the size of the // compressed data, which is always >0. If dst has length at least // CompressBlockBound(len(src)), compression always succeeds. Otherwise, the // first return value is zero if the compressed data does not fit in dst. func ( *CompressorCCompat) (, []byte) (int, error) { return .c.CompressBlock(, , .Acceleration) } // A CompressorHC compresses data into the LZ4 block format. // Its compression ratio is potentially better than that of a Compressor, // but it is also slower and requires more memory. // // A Compressor is not safe for concurrent use by multiple goroutines. // // Use a Writer to compress into the LZ4 stream format. type CompressorHC struct { // Level is the maximum search depth for compression. // Values <= 0 mean no maximum. Level CompressionLevel c lz4block.CompressorHC } // CompressBlock compresses the source buffer src into the destination dst. // // If compression is successful, the first return value is the size of the // compressed data, which is always >0. // // If dst has length at least CompressBlockBound(len(src)), compression always // succeeds. Otherwise, the first return value is zero. The error return is // non-nil if the compressed data does not fit in dst, but it might fit in a // larger buffer that is still smaller than CompressBlockBound(len(src)). The // return value (0, nil) means the data is likely incompressible and a buffer // of length CompressBlockBound(len(src)) should be passed in. func ( *CompressorHC) (, []byte) (int, error) { return .c.CompressBlock(, , lz4block.CompressionLevel(.Level)) } // CompressBlockHC is equivalent to CompressorHC.CompressBlock. // The final two arguments are ignored and should be set to nil. // // This function is deprecated. Use a CompressorHC instead. func (, []byte, CompressionLevel, , []int) (int, error) { return lz4block.CompressBlockHC(, , lz4block.CompressionLevel()) } const ( // ErrInvalidSourceShortBuffer is returned by UncompressBlock or CompressBLock when a compressed // block is corrupted or the destination buffer is not large enough for the uncompressed data. ErrInvalidSourceShortBuffer = lz4errors.ErrInvalidSourceShortBuffer // ErrInvalidFrame is returned when reading an invalid LZ4 archive. ErrInvalidFrame = lz4errors.ErrInvalidFrame // ErrInternalUnhandledState is an internal error. ErrInternalUnhandledState = lz4errors.ErrInternalUnhandledState // ErrInvalidHeaderChecksum is returned when reading a frame. ErrInvalidHeaderChecksum = lz4errors.ErrInvalidHeaderChecksum // ErrInvalidBlockChecksum is returned when reading a frame. ErrInvalidBlockChecksum = lz4errors.ErrInvalidBlockChecksum // ErrInvalidFrameChecksum is returned when reading a frame. ErrInvalidFrameChecksum = lz4errors.ErrInvalidFrameChecksum // ErrOptionInvalidCompressionLevel is returned when the supplied compression level is invalid. ErrOptionInvalidCompressionLevel = lz4errors.ErrOptionInvalidCompressionLevel // ErrOptionClosedOrError is returned when an option is applied to a closed or in error object. ErrOptionClosedOrError = lz4errors.ErrOptionClosedOrError // ErrOptionInvalidBlockSize is returned when ErrOptionInvalidBlockSize = lz4errors.ErrOptionInvalidBlockSize // ErrOptionNotApplicable is returned when trying to apply an option to an object not supporting it. ErrOptionNotApplicable = lz4errors.ErrOptionNotApplicable // ErrWriterNotClosed is returned when attempting to reset an unclosed writer. ErrWriterNotClosed = lz4errors.ErrWriterNotClosed // ErrWriterClosed is returned when writing to a closed writer. ErrWriterClosed = lz4errors.ErrWriterClosed // ErrInvalidFrameDescriptor is returned when reading a frame whose descriptor has an // unknown version, reserved bits set, or a dictionary ID. ErrInvalidFrameDescriptor = lz4errors.ErrInvalidFrameDescriptor // ErrInvalidContentSize is returned when reading a frame whose uncompressed size differs // from the content size in its descriptor, or when writing a frame whose data differs // from SizeOption. ErrInvalidContentSize = lz4errors.ErrInvalidContentSize )