Zip压缩字节数组

可以对dll或则是assetbundle进行压缩,减少大小

public class CompressUtil
{
    public static byte[] Compress(byte[] data)
    {
        using (var memoryStream = new MemoryStream())
        {
            using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
            {
                gzipStream.Write(data, 0, data.Length);
            }

            return memoryStream.ToArray();
        }
    }

    public static byte[] UnCompress(byte[] data)
    {
        using (var memoryStream = new MemoryStream(data))
        {
            using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
            {
                using (var output = new MemoryStream())
                {
                    gzipStream.CopyTo(output);
                    return output.ToArray();
                }
            }
        }
    }
}



首页 我的博客
粤ICP备17103704号