The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Compress and Decompress data using GZipStream
5 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.

Sonu ChaudharyPosted Feb 25, 2016, 7:17 AM
nice article
Tshifhiwa MudzusiPosted Sep 29, 2010, 8:55 AM
//decompress the data MemoryStream compressed = new MemoryStream(Buffer); MemoryStream uncompressed = new MemoryStream(); using (GZipStream s = new GZipStream(compressed,CompressionMode.Decompress)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { uncompressed.Write(data, 0, size); } else { break; } } }
Luu TaiPosted Sep 25, 2010, 4:18 AM
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 ?
Mohammad ElsheimyeditedPosted Apr 11, 2010, 5:16 PMEdited Apr 23, 2012, 2:21 AM
I previously wrote this article: http://www.c-sharpcorner.com/uploadfile/GemingLeader/programmatically-compress-and-decompress-files/.