The text of this article is not in this database — only its details are. Read it on the old site: Programmatically Compress and Decompress Files
1 Comment
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: Programmatically Compress and Decompress Files
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
Luu TaiPosted Sep 27, 2010, 8:53 PM
I have 2 problems 1. File's size is bigger after being compressed 2. I can't open a file after being decompressed this is my snipe code: FileStream fromFile = File.OpenRead("c:\\1.pdf"); FileStream toFile = File.Create("c:\\1.zaz"); GZipStream gZipStream = new GZipStream(toFile, CompressionMode.Compress); int mybyte = fromFile.ReadByte(); while (mybyte != -1) { gZipStream.WriteByte((byte)mybyte); mybyte = fromFile.ReadByte(); } Console.WriteLine("Compress completely"); gZipStream.Close(); // Gi?i nén file fromFile = File.OpenRead("c:\\1.zaz"); toFile = File.Create("c:\\2.pdf"); gZipStream = new GZipStream(fromFile, CompressionMode.Decompress); mybyte = gZipStream.ReadByte(); while (mybyte!=-1) { toFile.WriteByte((byte)mybyte); mybyte = gZipStream.ReadByte(); } gZipStream.Close(); Console.Write("Decompress completely"); Console.ReadLine(); May i code something wrong ?