Commit 0ce100dc authored by Vladimir Mihailenco's avatar Vladimir Mihailenco Committed by Joe Tsai

compress/flate: don't ignore dict in Reader.Reset

Fixes #16162.

Change-Id: I6f4ae906630079ef5fc29ee5f70e2e3d1c962170
Reviewed-on: https://go-review.googlesource.com/24390Reviewed-by: default avatarJoe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent db580210
......@@ -766,7 +766,7 @@ func (f *decompressor) Reset(r io.Reader, dict []byte) error {
dict: f.dict,
step: (*decompressor).nextBlock,
}
f.dict.init(maxMatchOffset, nil)
f.dict.init(maxMatchOffset, dict)
return nil
}
......
......@@ -37,3 +37,33 @@ func TestReset(t *testing.T) {
}
}
}
func TestResetDict(t *testing.T) {
dict := []byte("the lorem fox")
ss := []string{
"lorem ipsum izzle fo rizzle",
"the quick brown fox jumped over",
}
deflated := make([]bytes.Buffer, len(ss))
for i, s := range ss {
w, _ := NewWriterDict(&deflated[i], DefaultCompression, dict)
w.Write([]byte(s))
w.Close()
}
inflated := make([]bytes.Buffer, len(ss))
f := NewReader(nil)
for i := range inflated {
f.(Resetter).Reset(&deflated[i], dict)
io.Copy(&inflated[i], f)
}
f.Close()
for i, s := range ss {
if s != inflated[i].String() {
t.Errorf("inflated[%d]:\ngot %q\nwant %q", i, inflated[i], s)
}
}
}
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