MCPcopy
hub / github.com/google/go-containerregistry / PeekCompression

Function PeekCompression

internal/compression/compression.go:52–68  ·  view source on GitHub ↗

PeekCompression detects whether the input stream is compressed and which algorithm is used. If r implements Peek, we will use that directly, otherwise a small number of bytes are buffered to Peek at the gzip/zstd header, and the returned PeekReader can be used as a replacement for the consumed inpu

(r io.Reader)

Source from the content-addressed store, hash-verified

50// of bytes are buffered to Peek at the gzip/zstd header, and the returned
51// PeekReader can be used as a replacement for the consumed input io.Reader.
52func PeekCompression(r io.Reader) (compression.Compression, PeekReader, error) {
53 pr := intoPeekReader(r)
54
55 if isGZip, _, err := checkHeader(pr, gzip.MagicHeader); err != nil {
56 return compression.None, pr, err
57 } else if isGZip {
58 return compression.GZip, pr, nil
59 }
60
61 if isZStd, _, err := checkHeader(pr, zstd.MagicHeader); err != nil {
62 return compression.None, pr, err
63 } else if isZStd {
64 return compression.ZStd, pr, nil
65 }
66
67 return compression.None, pr, nil
68}
69
70// PeekReader is an io.Reader that also implements Peek a la bufio.Reader.
71type PeekReader interface {

Callers 2

GetCompressionFunction · 0.85
testPeekCompressionFunction · 0.85

Calls 2

intoPeekReaderFunction · 0.85
checkHeaderFunction · 0.85

Tested by 1

testPeekCompressionFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…