| | |
| | | |
| | | import( |
| | | "github.com/pierrec/lz4" |
| | | "fmt" |
| | | "github.com/long/test/logger" |
| | | ) |
| | | |
| | | |
| | |
| | | out := make([]byte, 10*len(in)) |
| | | n, err := lz4.UncompressBlock(in, out) |
| | | if err != nil { |
| | | fmt.Println("uncompress error: ", err) |
| | | logger.Error("uncompress error: ", err) |
| | | return nil, err |
| | | } |
| | | out = out[:n] // uncompressed data |
| | |
| | | ht := make([]int, 64<<10) // buffer for the compression table |
| | | n, err := lz4.CompressBlock(in, out, ht) |
| | | if err != nil { |
| | | fmt.Println("compress: ", err) |
| | | logger.Error("compress: ", err) |
| | | return nil, err |
| | | } |
| | | if n >= len(in) { |
| | | fmt.Println("image is not compressible") |
| | | logger.Error("image is not compressible") |
| | | } |
| | | out = out[:n] // compressed data |
| | | return out, nil |