Is there a way to decompress a DynaZip Max file with another library? F.E. DotNetZip

假如想象 提交于 2019-12-01 04:42:26

This code is from https://zlibnet.codeplex.com and it can decompress unencrypted DynaZip streams:

public static class DynazipCompressor
{
    const int DZ_DEFLATE_POS = 46;

    public static bool IsDynazip(byte[] source)
    {
        return source.Length >= 4 && BitConverter.ToInt32(source, 0) == 0x02014b50;
    }

    public static byte[] DeCompress(byte[] source)
    {
        if (!IsDynazip(source))
            throw new InvalidDataException("not dynazip header");
        using (MemoryStream srcStream = new MemoryStream(source, DZ_DEFLATE_POS, source.Length - DZ_DEFLATE_POS))
        using (MemoryStream dstStream = DeCompress(srcStream))
            return dstStream.ToArray();
    }

    private static MemoryStream DeCompress(Stream source)
    {
        MemoryStream dest = new MemoryStream();
        DeCompress(source, dest);
        dest.Position = 0;
        return dest;
    }

    private static void DeCompress(Stream source, Stream dest)
    {
        using (DeflateStream zsSource = new DeflateStream(source, CompressionMode.Decompress, true))
        {
            zsSource.CopyTo(dest);
        }
    }
}

A DynaZip stream is simply a DeflateStream with a PKZIP header, so this code just skip the header.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!