A PNG's IDAT data is not raw DEFLATE - it is wrapped in a small zlib envelope. Today you read and check the two-byte zlib header so the decoder knows the compressed stream is one it can handle.
Parse the two zlib header bytes and confirm they describe a valid deflate stream with no preset dictionary.
Concatenate a PNG’s IDAT chunk data and you get a zlib stream, not bare DEFLATE. Zlib adds a tiny frame: two header bytes up front and a four-byte checksum at the end. The header is CMF and FLG. In CMF the low nibble is the compression method (always 8, deflate, for PNG) and the high nibble is the window-size exponent (7 here, meaning a 32768-byte window). In FLG, bit 5 is FDICT, a preset-dictionary flag PNG never sets.
The clever part is the built-in check: the 16-bit value CMF*256 + FLG must be divisible by 31, a constraint the encoder satisfies by choosing the low FLG bits. 0x7801 passes (it is 31 * 992); 0x7800 does not. Reading these two bytes, confirming method 8 and no preset dictionary, and running the mod-31 check is all the zlib layer asks before you can reach the DEFLATE bitstream inside.
// CMF = b[0]: low nibble is method (must be 8), high nibble is window exponent.// FLG = b[1]: bit 5 is FDICT (preset dictionary). Header valid iff// (uint16(CMF)<<8 | FLG) % 31 == 0.func parseZlib(b []byte) (method int, window int, fdict bool, ok bool) { }