I keep track of the original size of the files that I'm compressing using .Net's GZipStream class, and it seems like the file that I thought I was compressing has increased in size. Is that possible?
This is how I'm doing the compression:
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);
}
}
Yes, it can. It has been fixed in .NET 4.
The compression algorithms for the System.IO.Compression..::.DeflateStream and System.IO.Compression..::.GZipStream classes have improved so that data that is already compressed is no longer inflated. This results in much better compression ratios. Also, the 4-gigabyte size restriction for compressing streams has been removed.
Check: GZipStream/DeflateStream increase file size on compression
Also check here SO: GZipStream and DeflateStream produce bigger files
Another reason could be that you include .git
folder when you compress, which inflates as you develop and use git.
For me, excluding .git
solved the problem.
精彩评论