using System.IO.Compression;
public static string FileName = "test.txt";
public static void Main()
string phrase = "The quick brown fox jumps over the lazy dog.";
byte[] bytesBeforeCompression = phrase.ToByteArray();
byte[] bytesAfterCompression = phrase.CompressGZip();
var orginalBytes = Decompress(bytesAfterCompression);
var file = FileName.ToFileInfo();
file.WriteAllBytes(orginalBytes);
Console.WriteLine(file.ReadAllText());
public static byte[] Decompress(byte[] data)
using (var compressedStream = new MemoryStream(data))
using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
using (var resultStream = new MemoryStream())
zipStream.CopyTo(resultStream);
return resultStream.ToArray();