Every PNG file begins with the same eight magic bytes. Today you build the smallest useful thing a decoder can do - recognize that a byte stream even claims to be a PNG - so the codec has a front door from day one.
Report whether a byte slice begins with the exact PNG signature.
Every PNG file opens with the same eight-byte signature: 89 50 4E 47 0D 0A 1A 0A. It is carefully chosen. The high bit of the first byte (0x89) catches transmission over channels that strip bit 7; the ASCII PNG (50 4E 47) is human-readable in a hex dump; and the 0D 0A, 1A, 0D 0A bytes detect the kinds of newline mangling and file truncation that plagued early binary formats.
You will not decode anything yet. You are building the one gate every decoder needs first: does this stream even claim to be a PNG? Anything that does not begin with these exact bytes is rejected before a single chunk is read. Pin the edges now - the wrong first byte fails, and a stream shorter than eight bytes fails rather than reading past its end.
// the fixed 8-byte PNG signaturevar Signature = []byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}func HasSignature(b []byte) bool {// true only if b starts with all eight signature bytes}