GZipStream和DeflateStream产生较大的文件 [英] GZipStream and DeflateStream produce bigger files

查看:344
本文介绍了GZipStream和DeflateStream产生较大的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#中使用放气/ gzip的流,但现在看来,压缩后的文件比以前大了。



例如,我压缩的docx的900ko文件,但它产生1.4Mo之一!



和它做它我想尽一切文件。



可能是我错了,我做的方式吗?这里是我的代码:

 的FileStream输入= File.OpenRead(Environment.CurrentDirectory +/file.docx); 
的FileStream输出= File.OpenWrite(Environment.CurrentDirectory +/compressedfile.dat);

GZipStream补偿=新GZipStream(输出,CompressionMode.Compress);

,而(input.Position = input.Length!)
comp.WriteByte((字节)input.ReadByte());

input.Close();

comp.Close(); //在收盘
output.Close自动调用flush();


解决方案

这么大的差别觉得奇怪,我,但你应该记住, DOCX 本身在ZIP压缩,因此没有理由再压缩它,结果通常是较大的。


I'm trying to use deflate/gzip streams in C# but it appears that the files after compression are bigger than before.

For example, I compress a docx file of 900ko, but it produce a 1.4Mo one !

And it does it for every file I tried.

May be I am wrong in the way I'm doing it? Here is my code :

  FileStream input = File.OpenRead(Environment.CurrentDirectory + "/file.docx");
  FileStream output = File.OpenWrite(Environment.CurrentDirectory + "/compressedfile.dat");

  GZipStream comp = new GZipStream(output, CompressionMode.Compress);

  while (input.Position != input.Length)
      comp.WriteByte((byte)input.ReadByte());

  input.Close();

  comp.Close(); // automatically call flush at closing
  output.Close();

解决方案

Such a big difference seems strange to me, but you should keep in mind that docx is itself compressed in ZIP, so there is no reason to compress it again, results usually are bigger.

这篇关于GZipStream和DeflateStream产生较大的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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