]> Cypherpunks repositories - gostls13.git/commitdiff
compress/flate: deprecate ReadError and WriteError
authorJoe Tsai <joetsai@digital-static.net>
Tue, 22 Sep 2015 08:33:11 +0000 (01:33 -0700)
committerNigel Tao <nigeltao@golang.org>
Sat, 10 Oct 2015 00:49:00 +0000 (00:49 +0000)
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>
src/compress/flate/flate_test.go
src/compress/flate/inflate.go

index f2362dd84fd2fcbb0ada6b40c845ac855b606782..341d807131351c6ea2a39969537b5e5d609ce687 100644 (file)
@@ -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)
                }
index cbc0181240b917f860360b98f661733b37afd3af..13855d6bc0c183c8a3e91eb0e783ca1c5a76b21b 100644 (file)
@@ -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