C#Gzip圧縮byte[](非書き換えアルゴリズム実装)

6543 ワード

C#Gzip圧縮byte[]


ダイレクトコード
// 
public static byte[] GZipBytes( byte[] data)
{
	using (var ms=new MemoryStream())
	{
		using (var gzipstream=new  GZipStream(ms,CompressionMode.Compress))
 		{
 			gzipstream.Write(data,0,data.Length);
			return ms.ToArray();
		}
	}
}
// 
 public static byte[] UGZipBytes(byte[] data)
        {
            using (var ms=new MemoryStream(data))
            {
                using (var gzs=new  GZipStream(ms,CompressionMode.Decompress))
                {
                    using (var outBuf=new MemoryStream())
                    {
                        byte[] tmp=new byte[1024];
                        int leng = 0;
                        while ((leng=gzs.Read(tmp,0,tmp.Length))>0)
                        {
                            outBuf.Write(tmp,0,leng);
                        }

                        return outBuf.ToArray();
                    }
                }
            }
        }