Skip to content

Commit

Permalink
gz/zlib/flate: Alias stdlib errors (#425)
Browse files Browse the repository at this point in the history
Better compatibility
  • Loading branch information
klauspost authored Aug 27, 2021
1 parent 290f4cf commit 501979b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
26 changes: 4 additions & 22 deletions flate/inflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ package flate

import (
"bufio"
"compress/flate"
"fmt"
"io"
"math/bits"
"strconv"
"sync"
)

Expand Down Expand Up @@ -41,11 +41,7 @@ var fixedOnce sync.Once
var fixedHuffmanDecoder huffmanDecoder

// A CorruptInputError reports the presence of corrupt input at a given offset.
type CorruptInputError int64

func (e CorruptInputError) Error() string {
return "flate: corrupt input before offset " + strconv.FormatInt(int64(e), 10)
}
type CorruptInputError = flate.CorruptInputError

// An InternalError reports an error in the flate code itself.
type InternalError string
Expand All @@ -55,26 +51,12 @@ func (e InternalError) Error() string { return "flate: internal error: " + strin
// 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
}

func (e *ReadError) Error() string {
return "flate: read error at offset " + strconv.FormatInt(e.Offset, 10) + ": " + e.Err.Error()
}
type ReadError = flate.ReadError

// 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
}

func (e *WriteError) Error() string {
return "flate: write error at offset " + strconv.FormatInt(e.Offset, 10) + ": " + e.Err.Error()
}
type WriteError = flate.WriteError

// Resetter resets a ReadCloser returned by NewReader or NewReaderDict to
// to switch to a new underlying Reader. This permits reusing a ReadCloser
Expand Down
6 changes: 3 additions & 3 deletions gzip/gunzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package gzip

import (
"bufio"
"compress/gzip"
"encoding/binary"
"errors"
"hash/crc32"
"io"
"time"
Expand All @@ -30,9 +30,9 @@ const (

var (
// ErrChecksum is returned when reading GZIP data that has an invalid checksum.
ErrChecksum = errors.New("gzip: invalid checksum")
ErrChecksum = gzip.ErrChecksum
// ErrHeader is returned when reading GZIP data that has an invalid header.
ErrHeader = errors.New("gzip: invalid header")
ErrHeader = gzip.ErrHeader
)

var le = binary.LittleEndian
Expand Down
8 changes: 4 additions & 4 deletions zlib/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package zlib

import (
"bufio"
"errors"
"compress/zlib"
"hash"
"hash/adler32"
"io"
Expand All @@ -37,11 +37,11 @@ const zlibDeflate = 8

var (
// ErrChecksum is returned when reading ZLIB data that has an invalid checksum.
ErrChecksum = errors.New("zlib: invalid checksum")
ErrChecksum = zlib.ErrChecksum
// ErrDictionary is returned when reading ZLIB data that has an invalid dictionary.
ErrDictionary = errors.New("zlib: invalid dictionary")
ErrDictionary = zlib.ErrDictionary
// ErrHeader is returned when reading ZLIB data that has an invalid header.
ErrHeader = errors.New("zlib: invalid header")
ErrHeader = zlib.ErrHeader
)

type reader struct {
Expand Down

0 comments on commit 501979b

Please sign in to comment.