C# Gzip解压

0x00.添加引用

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

0x01.解压

    public static string GZipDecompress(Stream stream)
    {
        byte[] buffer = new byte[100];
        int length = 0;

        GZipStream gzs = new GZipStream(stream, CompressionMode.Decompress);
        MemoryStream ms = new MemoryStream();

        while ((length = gzs.Read(buffer, 0, buffer.Length)) != 0)
        {
            ms.Write(buffer, 0, length);
        }
        return Encoding.UTF8.GetString(ms.ToArray());
    }
}