📜  c# gzip 字节数组 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:17.035000             🧑  作者: Mango

代码示例1
static byte[] Compress(byte[] data)
{
  using (var compressedStream = new MemoryStream())
  using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
  {
    zipStream.Write(data, 0, data.Length);
    zipStream.Close();
    return compressedStream.ToArray();
  }
}

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();
  }
}