but that obviously is not the right way.
Well obviously not, since you don't compare the bytes with anything. Otherwise, it pretty much is "right" as much as the Python program is.
A simple way to do the comparison is to interpret the bytes as unsigned char
:
auto up = reinterpret_cast<unsigned char*>(p);
if (up[0] == 0x1f && up[1] == 0x8b)
P.S. This is not necessarily the most accurate test for gzip files. It can have false positives.
I recommend not attempting to implement the test manually. There are open source libraries for this purpose (like there are for most purposes).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…