1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:00:09 -07:00

compress/zlib: actually use provided dictionary.

R=rsc, bradfitz, bradfitzgoog
CC=golang-dev
https://golang.org/cl/4518056
This commit is contained in:
Adam Langley 2011-05-11 17:00:19 -04:00
parent 158970ea66
commit d080a1cf14
2 changed files with 19 additions and 1 deletions

View File

@ -89,7 +89,7 @@ func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, os.Error) {
}
}
z.w = w
z.compressor = flate.NewWriter(w, level)
z.compressor = flate.NewWriterDict(w, level, dict)
z.digest = adler32.New()
return z, nil
}

View File

@ -5,6 +5,7 @@
package zlib
import (
"bytes"
"io"
"io/ioutil"
"os"
@ -121,3 +122,20 @@ func TestWriterDict(t *testing.T) {
}
}
}
func TestWriterDictIsUsed(t *testing.T) {
var input = []byte("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
buf := bytes.NewBuffer(nil)
compressor, err := NewWriterDict(buf, BestCompression, input)
if err != nil {
t.Errorf("error in NewWriterDict: %s", err)
return
}
compressor.Write(input)
compressor.Close()
const expectedMaxSize = 25
output := buf.Bytes()
if len(output) > expectedMaxSize {
t.Errorf("result too large (got %d, want <= %d bytes). Is the dictionary being used?", len(output), expectedMaxSize)
}
}