Commit fea18f5a authored by Nigel Tao's avatar Nigel Tao

compress/lzw: return the partial decoding for a truncated input.

This is needed by issue #9856.

Change-Id: Idad570a7e55ad903aab55372d390bc746c4e19cf
Reviewed-on: https://go-review.googlesource.com/11661Reviewed-by: default avatarRob Pike <r@golang.org>
parent 53eb4783
......@@ -139,6 +139,7 @@ func (d *decoder) decode() {
err = io.ErrUnexpectedEOF
}
d.err = err
d.flush()
return
}
switch {
......@@ -190,6 +191,7 @@ func (d *decoder) decode() {
}
default:
d.err = errors.New("lzw: invalid code")
d.flush()
return
}
d.last, d.hi = code, d.hi+1
......
......@@ -98,13 +98,20 @@ func TestReader(t *testing.T) {
defer rc.Close()
b.Reset()
n, err := io.Copy(&b, rc)
s := b.String()
if err != nil {
if err != tt.err {
t.Errorf("%s: io.Copy: %v want %v", tt.desc, err, tt.err)
}
if err == io.ErrUnexpectedEOF {
// Even if the input is truncated, we should still return the
// partial decoded result.
if n == 0 || !strings.HasPrefix(tt.raw, s) {
t.Errorf("got %d bytes (%q), want a non-empty prefix of %q", n, s, tt.raw)
}
}
continue
}
s := b.String()
if s != tt.raw {
t.Errorf("%s: got %d-byte %q want %d-byte %q", tt.desc, n, s, len(tt.raw), tt.raw)
}
......
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