Commit 2002d66d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c1f86a48
...@@ -45,10 +45,9 @@ deco/unzlib/go/prod1-max 542µs ± 0% 262µs ± 0% -51.71% (p=0.008 ...@@ -45,10 +45,9 @@ deco/unzlib/go/prod1-max 542µs ± 0% 262µs ± 0% -51.71% (p=0.008
"github.com/DataDog/czlib" "github.com/DataDog/czlib"
) )
// Compress compresses data according to zlib encoding. // Compress compresses data according to zlib encoding.
// //
// XXX default level is used, etc. // default level and dictionary are used.
func Compress(data []byte) (zdata []byte) { func Compress(data []byte) (zdata []byte) {
var b bytes.Buffer var b bytes.Buffer
w := zlib.NewWriter(&b) w := zlib.NewWriter(&b)
...@@ -112,8 +111,8 @@ func zlibFreeReader(r zlibReader) { ...@@ -112,8 +111,8 @@ func zlibFreeReader(r zlibReader) {
// if out has not enough capacity a new buffer is allocated and used. // if out has not enough capacity a new buffer is allocated and used.
// //
// return: destination buffer with full decompressed data or error. // return: destination buffer with full decompressed data or error.
func Decompress(in []byte, out []byte) (data []byte, err error) { func Decompress(zdata []byte, out []byte) (data []byte, err error) {
bin := bytes.NewReader(in) bin := bytes.NewReader(zdata)
zr, err := zlibNewReader(bin) zr, err := zlibNewReader(bin)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -127,7 +126,7 @@ func Decompress(in []byte, out []byte) (data []byte, err error) { ...@@ -127,7 +126,7 @@ func Decompress(in []byte, out []byte) (data []byte, err error) {
zlibFreeReader(zr) zlibFreeReader(zr)
}() }()
bout := bytes.NewBuffer(out) bout := bytes.NewBuffer(out[:0])
_, err = io.Copy(bout, zr) _, err = io.Copy(bout, zr)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -25,7 +25,7 @@ import ( ...@@ -25,7 +25,7 @@ import (
"github.com/kylelemons/godebug/pretty" "github.com/kylelemons/godebug/pretty"
) )
var ztestv = []struct{in, out string}{ var ztestv = []struct{ in, out string }{
{ {
in: "x\x9c\xf3H\xcd\xc9\xc9W\x08\xcf/\xcaIQ\x04\x00\x1cI\x04>", in: "x\x9c\xf3H\xcd\xc9\xc9W\x08\xcf/\xcaIQ\x04\x00\x1cI\x04>",
out: "Hello World!", out: "Hello World!",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment