在c#中压缩字节[]

问题描述 投票:0回答:1

我有一个解压缩字节数组的方法,并且我需要与此功能相反的方法(平均压缩)。我做了很多事情,但没有发现与该功能完全相反的方法

public static byte[] Decompress(byte[] B)
{

        MemoryStream ms = new MemoryStream(B);
        GZipStream gzipStream = new GZipStream((Stream)ms, CompressionMode.Decompress);
        byte[] buffer = new byte[4];
        ms.Position = checked(ms.Length - 5L);
        ms.Read(buffer, 0, 4);
        int count = BitConverter.ToInt32(buffer, 0);
        ms.Position = 0L;
        byte[] AR = new byte[checked(count - 1 + 1)];
        gzipStream.Read(AR, 0, count);
        gzipStream.Dispose();
        ms.Dispose();
        return AR;

}
c# compression gzip memorystream bitconverter
1个回答
0
投票

您已经使解压缩部分复杂化了。您可以通过纯粹的流和复制来实现大部分所需的功能。

© www.soinside.com 2019 - 2024. All rights reserved.