public static byte[] CompressGZip(byte[] raw) { using (MemoryStream memory = new MemoryStream()) { using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress, false)) { gzip.Write(raw, 0, raw.Length); } return memory.ToArray(); } }