valyala / gozstd

go wrapper for zstd
MIT License
420 stars 60 forks source link

byte size grow after compress #29

Closed chenjiandongx closed 3 years ago

chenjiandongx commented 3 years ago

Hi @valyala

There is a case that makes me confused. Why byte size grow after compress? the example code is below.

package main

import (
    "fmt"

    "github.com/valyala/gozstd"
)

func main() {
    data := []byte{0, 0, 253, 53, 0, 1, 3, 197, 161, 198, 102, 102, 102, 106, 3, 226, 127, 42, 170, 170, 170, 239, 114, 223, 255, 255, 255, 229, 234, 92, 170, 170, 170, 170, 189, 203, 230, 102, 102, 102, 119, 153, 184, 204, 204, 204, 205, 68, 170, 170, 170, 171, 189, 77, 191, 255, 255, 255, 202, 74, 170, 170, 170, 169, 222, 159, 115, 51, 51, 51, 58, 24, 204, 204, 204, 205, 32, 149, 85, 85, 85, 114, 59, 255, 255, 255, 252, 160, 149, 85, 85, 85, 82, 31, 51, 51, 51, 51, 160, 140, 204, 204, 204, 210, 121, 85, 85, 85, 87, 32, 191, 255, 255, 255, 202, 25, 85, 85, 85, 85, 35, 115, 51, 51, 51, 63, 255, 255, 255, 255, 128}
    fmt.Println("len before compress:", len(data))
    compressedData := gozstd.Compress(nil, data)
    fmt.Println("len after compress:", len(compressedData))
}

Output:

len before compress: 131
len after compress: 140

how can I reduce the byte sizes and compress them actually?