有没有办法知道 byte[] 是否已被 GzipStream
.net 类压缩(或未压缩)?
编辑: 只想知道 byte[] 数组是否被压缩(因为我总是使用 GzipStream 来压缩和解压)
最佳答案
A GZipStream是 DeflateStream有一个额外的标题和预告片。
格式在RFC 1952中指定.
.NET 4.0 GZipStream类将以下字节写入标题:
byte[] headerBytes = new byte[] { 0x1f, 0x8b, 8, 0, 0, 0, 0, 0, 4, 0 };
if (compressionLevel == 10)
{
headerBytes[8] = 2;
}
预告片包含 CRC32校验和和未压缩数据的长度。
关于c# - 有没有办法知道 byte[] 是否已被 gzipstream 压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4662821/