compression

package
v1.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compression provides the deflate decoding shared by the engine's buffered pipeline and the fingerprint transport adapter, so the two paths cannot drift on zlib sniffing: RFC 9110's canonical "deflate" form is zlib-wrapped, while some legacy servers send raw deflate.

Index

Constants

This section is empty.

Variables

View Source
var ErrZlibUnsupported = errors.New("deflate: zlib stream requires preset dictionary or oversized window")

ErrZlibUnsupported reports a zlib-shaped deflate stream the stdlib reader cannot decode: preset dictionary (FDICT) or window size above 32K.

Functions

func NewDeflateReader

func NewDeflateReader(r io.Reader) (io.ReadCloser, error)

NewDeflateReader decodes a "Content-Encoding: deflate" body: zlib-wrapped (the RFC 9110 canonical form) or raw deflate (legacy server quirk), chosen by a non-consuming header sniff. ErrZlibUnsupported is returned for FDICT / oversized-window zlib streams instead of decoding from the wrong offset.

Types

type ZlibSniff

type ZlibSniff int

ZlibSniff classifies a stream's two-byte zlib header.

const (
	// SniffNotZlib reports a stream that is not zlib-shaped (fewer than two
	// readable bytes, another compression method, or failed FCHECK): the
	// caller decodes it as raw flate.
	SniffNotZlib ZlibSniff = iota
	// SniffZlib reports a header the stdlib zlib reader will accept.
	SniffZlib
	// SniffZlibUnsupported reports a zlib-shaped header the stdlib reader
	// rejects. Decoding must FAIL here: zlib.NewReader drains 2-6 header
	// bytes before failing, so a raw-flate fallback would resume mid-payload
	// and silently produce wrong bytes.
	SniffZlibUnsupported
)

func ClassifyZlib

func ClassifyZlib(br *bufio.Reader) ZlibSniff

ClassifyZlib inspects the first two bytes of br without consuming them, so a decoder started on br afterwards still sees the complete stream. An unreadable or short stream classifies as SniffNotZlib; its real error surfaces from the eventual decoder. The *bufio.Reader parameter is deliberate: Peek only avoids consumption when the caller keeps decoding from the same buffered reader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL