Gzip格式判断

2021-09-05  本文已影响0人  舍是境界

这里介绍Gzip格式判断代码,逻辑其实是一致的,对Gzip内部格式感兴趣的同学,可以参考Gzip Documention

public static boolean isGzipped(byte[] input){
        if (input.length < 2) {
            return false;
        }
        
        return (input[0] & 0xff | (input[1] << 8 & 0xff00)) == GZIPInputStream.GZIP_MAGIC;
    }
func IsGzipped(input []byte) bool {
    if len(input) < 2 {
        return false
    }

    return (int64(input[0]) & 0xff | (int64(input[1] << 8) & 0xff00)) == 0x8b1f
}
上一篇 下一篇

猜你喜欢

热点阅读