使用GZIP可使文件更大!! [英] Using GZIP make the file size larger!!

查看:99
本文介绍了使用GZIP可使文件更大!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


tittle说了所有事情,我尝试通过代码压缩来压缩和增加文件的大小,但是它使文件的大小变大了(500mb至950mb !!!)
代码:

Hi,
tittle says every thing, I tried to compress and increase the size of a file with code blow but it made it''s size larger (500mb to 950mb !!!!)
Code :

     byte[] buffer = new byte[1];
                    sread = new System.IO.FileStream(@"C:\Users\mm\Desktop\code.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    swrite = new System.IO.FileStream(@"C:\Users\mm\Desktop\0.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);

                    System.IO.Compression.GZipStream g = new     System.IO.Compression.GZipStream(swrite, System.IO.Compression.CompressionMode.Compress,true);

br = new System.IO.BinaryReader(sread);
bw = new System.IO.BinaryWriter(swrite);
while (true)
{
    try
    {
        buffer= br.ReadBytes(1);
        g.Write(buffer, 0, 1);
    }
    catch { break; }
}
sread.Close();
swrite.Close();
br.Close();
bw.Close();





我怎么做对了?
谢谢.





How can I make it right??
Thanks.

推荐答案

我想您没有正确使用GZipStream类.为什么不遵循安全路径(即MSDN代码示例,可能会找到
I suppose you are not properly using the GZipStream class. Why don''t you follow the safe path (namely the MSDN code sample you may find here[^])?


我刚刚运行了一些测试,怀疑问题出在您的每次读写操作中使用了一个字节.尝试使用更大的缓冲区,看看会得到什么结果.
I have just run some tests and suspect that the problem is due to you using a single byte for each read and write operation. Try using a larger buffer and see what results you get.


这篇关于使用GZIP可使文件更大!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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