mirror of
https://github.com/golang/go
synced 2024-11-24 01:30:10 -07:00
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 <nigeltao@golang.org>
This commit is contained in:
parent
a0c7f57903
commit
2d5601d85c
@ -267,9 +267,6 @@ func TestTruncatedStreams(t *testing.T) {
|
|||||||
for i := 0; i < len(data)-1; i++ {
|
for i := 0; i < len(data)-1; i++ {
|
||||||
r := NewReader(strings.NewReader(data[:i]))
|
r := NewReader(strings.NewReader(data[:i]))
|
||||||
_, err := io.Copy(ioutil.Discard, r)
|
_, err := io.Copy(ioutil.Discard, r)
|
||||||
if ferr, ok := err.(*ReadError); ok {
|
|
||||||
err = ferr.Err
|
|
||||||
}
|
|
||||||
if err != io.ErrUnexpectedEOF {
|
if err != io.ErrUnexpectedEOF {
|
||||||
t.Errorf("io.Copy(%d) on truncated stream: got %v, want %v", i, 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) }
|
func (e InternalError) Error() string { return "flate: internal error: " + string(e) }
|
||||||
|
|
||||||
// A ReadError reports an error encountered while reading input.
|
// A ReadError reports an error encountered while reading input.
|
||||||
|
//
|
||||||
|
// Deprecated: No longer returned.
|
||||||
type ReadError struct {
|
type ReadError struct {
|
||||||
Offset int64 // byte offset where error occurred
|
Offset int64 // byte offset where error occurred
|
||||||
Err error // error returned by underlying Read
|
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.
|
// A WriteError reports an error encountered while writing output.
|
||||||
|
//
|
||||||
|
// Deprecated: No longer returned.
|
||||||
type WriteError struct {
|
type WriteError struct {
|
||||||
Offset int64 // byte offset where error occurred
|
Offset int64 // byte offset where error occurred
|
||||||
Err error // error returned by underlying Write
|
Err error // error returned by underlying Write
|
||||||
@ -640,7 +644,7 @@ func (f *decompressor) dataBlock() {
|
|||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
f.err = &ReadError{f.roffset, err}
|
f.err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n := int(f.buf[0]) | int(f.buf[1])<<8
|
n := int(f.buf[0]) | int(f.buf[1])<<8
|
||||||
@ -675,7 +679,7 @@ func (f *decompressor) copyData() {
|
|||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
f.err = &ReadError{f.roffset, err}
|
f.err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n -= m
|
n -= m
|
||||||
|
Loading…
Reference in New Issue
Block a user