diff options
| author | 2025-11-22 08:00:00 +0800 | |
|---|---|---|
| committer | 2025-11-22 08:00:00 +0800 | |
| commit | a504524ca695f04692f5a2cf49952ed039a6a348 (patch) | |
| tree | 4d0ab8463f1bd9be22aab2af7b7d38f88ef24c77 /internal/zlibx | |
| parent | bufpool: Improve perf by using buckets of different size classes (diff) | |
| signature | No signature | |
bufpool: Return *Buffer
Diffstat (limited to 'internal/zlibx')
| -rw-r--r-- | internal/zlibx/decompress.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/internal/zlibx/decompress.go b/internal/zlibx/decompress.go index c6eb65e5..68a92587 100644 --- a/internal/zlibx/decompress.go +++ b/internal/zlibx/decompress.go @@ -11,71 +11,71 @@ import ( // Decompress inflates the provided zlib wrapped stream and returns the // uncompressed data inside a pooled bufpool.Buffer. -func Decompress(src []byte) (bufpool.Buffer, error) { +func Decompress(src []byte) (*bufpool.Buffer, error) { return DecompressSized(src, 0) } // DecompressSized inflates the provided zlib stream, using sizeHint to // preallocate the output buffer when known (e.g. packfile entries). -func DecompressSized(src []byte, sizeHint int) (bufpool.Buffer, error) { +func DecompressSized(src []byte, sizeHint int) (*bufpool.Buffer, error) { return DecompressDictSized(src, nil, sizeHint) } // DecompressDict is like Decompress but accepts a preset dictionary. The // dictionary must match the checksum embedded in the stream if the dictionary // flag is present. -func DecompressDict(src []byte, dict []byte) (bufpool.Buffer, error) { +func DecompressDict(src []byte, dict []byte) (*bufpool.Buffer, error) { return DecompressDictSized(src, dict, 0) } // DecompressDictSized is like DecompressDict but allows providing an expected // uncompressed size to avoid buffer growth copies. -func DecompressDictSized(src []byte, dict []byte, sizeHint int) (bufpool.Buffer, error) { +func DecompressDictSized(src []byte, dict []byte, sizeHint int) (*bufpool.Buffer, error) { if len(src) < 6 { - return bufpool.Buffer{}, io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } cmf := src[0] flg := src[1] if (cmf&0x0f != zlibDeflate) || (cmf>>4 > zlibMaxWindow) || (binary.BigEndian.Uint16(src[:2])%31 != 0) { - return bufpool.Buffer{}, ErrHeader + return nil, ErrHeader } offset := 2 haveDict := flg&0x20 != 0 if haveDict { if len(src) < offset+4 { - return bufpool.Buffer{}, io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } if dict == nil { - return bufpool.Buffer{}, ErrDictionary + return nil, ErrDictionary } checksum := binary.BigEndian.Uint32(src[offset : offset+4]) if checksum != adler32.Checksum(dict) { - return bufpool.Buffer{}, ErrDictionary + return nil, ErrDictionary } offset += 4 } if len(src[offset:]) < 4 { - return bufpool.Buffer{}, io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } deflateData := src[offset:] out, consumed, err := flatex.DecompressDictSized(deflateData, dict, sizeHint) if err != nil { - return bufpool.Buffer{}, err + return nil, err } checksumPos := offset + consumed if checksumPos+4 > len(src) { out.Release() - return bufpool.Buffer{}, io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } expected := binary.BigEndian.Uint32(src[checksumPos : checksumPos+4]) if expected != adler32.Checksum(out.Bytes()) { out.Release() - return bufpool.Buffer{}, ErrChecksum + return nil, ErrChecksum } return out, nil } |
