GZip压缩(通过.net)可以增加文件大小吗?

问题描述 投票:3回答:2

我使用.Net的GZipStream类跟踪我正在压缩的文件的原始大小,看起来我认为我压缩的文件的大小已经增加了。那可能吗?

这就是我正在进行压缩的方式:

Byte[] bytes = GetFileBytes(file);

using (FileStream fileStream = new FileStream("Zipped.gz", FileMode.Create))
{
    using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Compress))
    {
        zipStream.Write(bytes, 0, bytes.Length);
    }
}
.net compression gzip filesize gzipstream
2个回答
4
投票

是的,它可以。它一直是fixed in .NET 4

System.IO.Compression .. ::。DeflateStream和System.IO.Compression .. ::。GZipStream类的压缩算法已得到改进,因此已压缩的数据不再膨胀。这导致更好的压缩比。此外,已经消除了用于压缩流的4千兆字节大小的限制。

检查:GZipStream/DeflateStream increase file size on compression

另请查看SO:GZipStream and DeflateStream produce bigger files


0
投票

另一个原因可能是你在压缩时包含.git文件夹,在你开发和使用git时会膨胀。

对我来说,排除.git解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.