有没有办法知道byte []是否被gzipstream压缩? [英] Is there a way to know if the byte[] has been compressed by gzipstream?

查看:815
本文介绍了有没有办法知道byte []是否被gzipstream压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道byte []是否被 GzipStream .net类压缩(或未压缩)?

Is there a way to know if the byte[] has been compressed (or not) by GzipStream .net class?

编辑:
只是想知道byte []数组是否已经压缩(因为我将始终使用GzipStream压缩和解压缩)

Just want to know if the byte[] array has been compressed (since I will always be using GzipStream to compress and decompress)

推荐答案

A GZipStream 是一个 DeflateStream 添加一个标题和尾部。

A GZipStream is a DeflateStream with an additional header and trailer.

格式在 RFC 1952

.NET 4.0 GZipStream 类别将以下字节写为标题:

The .NET 4.0 GZipStream class writes the following bytes as header:

byte[] headerBytes = new byte[] { 0x1f, 0x8b, 8, 0, 0, 0, 0, 0, 4, 0 };
if (compressionLevel == 10)
{
    headerBytes[8] = 2;
}

预告片包含 CRC32 校验和和未压缩数据的长度。

The trailer consists of a CRC32 checksum and the length of the uncompressed data.

这篇关于有没有办法知道byte []是否被gzipstream压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆