Skip to content

Commit 2d5601d

Browse files
dsnetnigeltao
authored andcommitted
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/14834 Reviewed-by: Nigel Tao <[email protected]>
1 parent a0c7f57 commit 2d5601d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/compress/flate/flate_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,6 @@ func TestTruncatedStreams(t *testing.T) {
267267
for i := 0; i < len(data)-1; i++ {
268268
r := NewReader(strings.NewReader(data[:i]))
269269
_, err := io.Copy(ioutil.Discard, r)
270-
if ferr, ok := err.(*ReadError); ok {
271-
err = ferr.Err
272-
}
273270
if err != io.ErrUnexpectedEOF {
274271
t.Errorf("io.Copy(%d) on truncated stream: got %v, want %v", i, err, io.ErrUnexpectedEOF)
275272
}

src/compress/flate/inflate.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ type InternalError string
4242
func (e InternalError) Error() string { return "flate: internal error: " + string(e) }
4343

4444
// A ReadError reports an error encountered while reading input.
45+
//
46+
// Deprecated: No longer returned.
4547
type ReadError struct {
4648
Offset int64 // byte offset where error occurred
4749
Err error // error returned by underlying Read
@@ -52,6 +54,8 @@ func (e *ReadError) Error() string {
5254
}
5355

5456
// A WriteError reports an error encountered while writing output.
57+
//
58+
// Deprecated: No longer returned.
5559
type WriteError struct {
5660
Offset int64 // byte offset where error occurred
5761
Err error // error returned by underlying Write
@@ -640,7 +644,7 @@ func (f *decompressor) dataBlock() {
640644
if err == io.EOF {
641645
err = io.ErrUnexpectedEOF
642646
}
643-
f.err = &ReadError{f.roffset, err}
647+
f.err = err
644648
return
645649
}
646650
n := int(f.buf[0]) | int(f.buf[1])<<8
@@ -675,7 +679,7 @@ func (f *decompressor) copyData() {
675679
if err == io.EOF {
676680
err = io.ErrUnexpectedEOF
677681
}
678-
f.err = &ReadError{f.roffset, err}
682+
f.err = err
679683
return
680684
}
681685
n -= m

0 commit comments

Comments
 (0)