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 ¶
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 ¶
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.