Created
January 4, 2011 10:53
-
-
Save markandey/764648 to your computer and use it in GitHub Desktop.
Simple Compress and Decompress in C#.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.IO.Compression; | |
class Qompress | |
{ | |
public static byte[] CompressBuffer(byte[] byteArray) | |
{ | |
MemoryStream strm = new MemoryStream(); | |
GZipStream GZipStrem = new GZipStream(strm, CompressionMode.Compress, true); | |
GZipStrem.Write(byteArray, 0, byteArray.Length); | |
GZipStrem.Flush(); | |
strm.Flush(); | |
byte[] ByteArrayToreturn= strm.GetBuffer(); | |
GZipStrem.Close(); | |
strm.Close(); | |
return ByteArrayToreturn; | |
} | |
public static byte[] DeCompressBuffer(byte[] byteArray) | |
{ | |
MemoryStream strm = new MemoryStream(byteArray); | |
GZipStream GZipStrem = new GZipStream(strm, CompressionMode.Decompress,true); | |
List<byte> ByteListUncompressedData = new List<byte>(); | |
int bytesRead = GZipStrem.ReadByte(); | |
while (bytesRead != -1) | |
{ | |
ByteListUncompressedData.Add((byte)bytesRead); | |
bytesRead = GZipStrem.ReadByte(); | |
} | |
GZipStrem.Flush(); | |
strm.Flush(); | |
GZipStrem.Close(); | |
strm.Close(); | |
return ByteListUncompressedData.ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment