Commit 2d5601d8 authored by Joe Tsai's avatar Joe Tsai Committed by Nigel Tao

compress/flate: deprecate ReadError and WriteError

A vast majority of the time, ReadError isn't even returned during
IO operations. Instead, an unwrapped error will be returned because
of the ReadByte call on L705. Because DEFLATE streams are primarily
compressed and require byte for byte Huffman decoding, most of the
data read from a data stream will go through ReadByte.

Although this is technically an API change, any user reliant on
this error would not have worked properly anyways due to the fact
that most IO error are not wrapped. We might as well deprecate
ReadError. It is useless and actually makes clients that do
depend on catching IO errors more difficult.

Fixes #11856
Fixes #12724

Change-Id: Ib5fec5ae215e977c4e85de5701ce6a473d400af8
Reviewed-on: https://go-review.googlesource.com/14834Reviewed-by: 's avatarNigel Tao <nigeltao@golang.org>
parent a0c7f579
......@@ -267,9 +267,6 @@ func TestTruncatedStreams(t *testing.T) {
for i := 0; i < len(data)-1; i++ {
r := NewReader(strings.NewReader(data[:i]))
_, err := io.Copy(ioutil.Discard, r)
if ferr, ok := err.(*ReadError); ok {
err = ferr.Err
}
if err != io.ErrUnexpectedEOF {
t.Errorf("io.Copy(%d) on truncated stream: got %v, want %v", i, err, io.ErrUnexpectedEOF)
}
......
......@@ -42,6 +42,8 @@ type InternalError string
func (e InternalError) Error() string { return "flate: internal error: " + string(e) }
// A ReadError reports an error encountered while reading input.
//
// Deprecated: No longer returned.
type ReadError struct {
Offset int64 // byte offset where error occurred
Err error // error returned by underlying Read
......@@ -52,6 +54,8 @@ func (e *ReadError) Error() string {
}
// A WriteError reports an error encountered while writing output.
//
// Deprecated: No longer returned.
type WriteError struct {
Offset int64 // byte offset where error occurred
Err error // error returned by underlying Write
......@@ -640,7 +644,7 @@ func (f *decompressor) dataBlock() {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
f.err = &ReadError{f.roffset, err}
f.err = err
return
}
n := int(f.buf[0]) | int(f.buf[1])<<8
......@@ -675,7 +679,7 @@ func (f *decompressor) copyData() {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
f.err = &ReadError{f.roffset, err}
f.err = err
return
}
n -= m
......
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