gitee.com/h79/goutils@v1.22.10/common/compress/lz4.go (about)

     1  package compress
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/hungys/go-lz4"
     6  )
     7  
     8  type LZ4 struct{}
     9  
    10  // Name returns name of the algorithm LZ4
    11  func (l LZ4) Name() string { return "LZ4" }
    12  
    13  // CompressBound max size of compressed data
    14  func (l LZ4) CompressBound(size int) int { return lz4.CompressBound(size) }
    15  
    16  // Compress using LZ4 algorithm
    17  func (l LZ4) Compress(dst, src []byte) (int, error) {
    18  	return lz4.CompressDefault(src, dst)
    19  }
    20  
    21  // Decompress using LZ4 algorithm
    22  func (l LZ4) Decompress(dst, src []byte) (int, error) {
    23  	if len(src) == 0 {
    24  		return 0, fmt.Errorf("decompress an empty input")
    25  	}
    26  	return lz4.DecompressSafe(src, dst)
    27  }