Skip to content

Commit

Permalink
compress/flate: deprecate ReadError and WriteError
Browse files Browse the repository at this point in the history
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 golang#11856
Fixes golang#12724

Change-Id: Ib5fec5ae215e977c4e85de5701ce6a473d400af8
Reviewed-on: https://go-review.googlesource.com/14834
Reviewed-by: Nigel Tao <[email protected]>
  • Loading branch information
dsnet authored and nigeltao committed Oct 10, 2015
1 parent a0c7f57 commit 2d5601d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/compress/flate/flate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions src/compress/flate/inflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d5601d

Please sign in to comment.