Skip to main content

Posts

Showing posts with the label Compression

Compressing Streams in .Net

Namespace: System.IO.Compression There are two types of compression streams, GZip and Deflate . GZip leaves a standard header information block that can be used by the tools like Gzip to decompress the information. Deflate does not leaves any header information thus it is only decompressed by the respective application only. Both streams can only compress 4GB of uncompressed data. FileStream source = new FileStream(@“C:\file.dat”); FileStream destination = new FileStream(@“C:\file.gzip”); GZipStream Gs = new GZipStream(destination, CompressionMode.Compress); int b = source.ReadByte(); While(b!=-1) {                 Gs.WriteByte((byte)b);                 b = source.ReadByte(); } And to decompress a compressed file : FileStream source = new FileStream(@“ C:\file.gzip ”);   //reversed ...