MCPcopy Create free account
hub / github.com/buggregator/server / decompress

Function decompress

modules/sentry/handler.go:304–338  ·  view source on GitHub ↗

decompress handles gzip and deflate Content-Encoding. Also auto-detects gzip/zlib by magic bytes if header is missing.

(data []byte, encoding string)

Source from the content-addressed store, hash-verified

302// decompress handles gzip and deflate Content-Encoding.
303// Also auto-detects gzip/zlib by magic bytes if header is missing.
304func decompress(data []byte, encoding string) []byte {
305 if len(data) == 0 {
306 return data
307 }
308
309 // Try by Content-Encoding header first.
310 switch strings.ToLower(encoding) {
311 case "gzip":
312 if d, err := decompressGzip(data); err == nil {
313 return d
314 }
315 case "deflate":
316 if d, err := decompressZlib(data); err == nil {
317 return d
318 }
319 }
320
321 // Auto-detect by magic bytes (Sentry SDKs sometimes omit the header).
322 if len(data) >= 2 {
323 // Gzip magic: 0x1f 0x8b
324 if data[0] == 0x1f && data[1] == 0x8b {
325 if d, err := decompressGzip(data); err == nil {
326 return d
327 }
328 }
329 // Zlib magic: 0x78 (0x01, 0x5e, 0x9c, 0xda)
330 if data[0] == 0x78 {
331 if d, err := decompressZlib(data); err == nil {
332 return d
333 }
334 }
335 }
336
337 return data
338}
339
340func decompressGzip(data []byte) ([]byte, error) {
341 r, err := gzip.NewReader(bytes.NewReader(data))

Callers 2

HandleMethod · 0.85
TestDecompressFunction · 0.85

Calls 2

decompressGzipFunction · 0.85
decompressZlibFunction · 0.85

Tested by 1

TestDecompressFunction · 0.68