Copy codeThe Code is as follows:
Public static class Compressor {
Public static byte [] Compress (byte [] data)
{
Using (MemoryStream output = new MemoryStream ())
{
Using (GZipStream gzip = new GZipStream (output, CompressionMode. Compress, true ))
{
Gzip. Write (data, 0, data. Length );
Gzip. Close ();
Return output. ToArray ();
}
}
}
Public static byte [] Decompress (byte [] data)
{
Using (MemoryStream input = new MemoryStream ())
{
Input. Write (data, 0, data. Length );
Input. Position = 0;
Using (GZipStream gzip = new GZipStream (input, CompressionMode. Decompress, true ))
{
Using (MemoryStream output = new MemoryStream ())
{
Byte [] buff = new byte [64];
Int read =-1;
Read = gzip. Read (buff, 0, buff. Length );
While (read> 0)
{
Output. Write (buff, 0, read );
Read = gzip. Read (buff, 0, buff. Length );
}
Gzip. Close ();
Return output. ToArray ();
}
}
}
}