如何使用ICSharpCode.ZipLib与流? [英] How to use ICSharpCode.ZipLib with stream?

查看:184
本文介绍了如何使用ICSharpCode.ZipLib与流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是保守的标题,我的问题本身很抱歉,但我迷路了。

I'm very sorry for the conservative title and my question itself,but I'm lost.

样品我在寻找。
我想通过把它的InflaterInputStream(ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream)

The samples provided with ICsharpCode.ZipLib doesn't include what I'm searching for. I want to decompress a byte[] by putting it in InflaterInputStream(ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream)

我发现了一个解压缩功能来解压一个byte [] ,但它不能正常工作。

I found a decompress function ,but it doesn't work.

    public static byte[] Decompress(byte[] Bytes)
    {
        ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream stream =
            new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(new MemoryStream(Bytes));
        MemoryStream memory = new MemoryStream();
        byte[] writeData = new byte[4096];
        int size;

        while (true)
        {
            size = stream.Read(writeData, 0, writeData.Length);
            if (size > 0)
            {
                memory.Write(writeData, 0, size);
            }
            else break;
        }
        stream.Close();
        return memory.ToArray();
    }



在这行抛出异常(大小= stream.Read(writeData,0 ,writeData.Length);)说,它有一个无效的头

It throws an exception at line(size = stream.Read(writeData, 0, writeData.Length);) saying it has a invalid header.

我的问题不在于如何修复功能,这个功能不仅仅是提供图书馆,我发现googling.My问题是,如何解压缩以同样的方式与InflaterStream该函数,但没有例外

My question is not how to fix the function,this function is not provided with the library,I just found it googling.My question is,how to decompress the same way the function does with InflaterStream,but without exceptions.

感谢,并再次 - 。比较遗憾的是保守的问题

Thanks and again - sorry for the conservative question.

推荐答案

那么它听起来像数据仅仅是不合适的,否则该代码将工作正常。 (诚​​然,我会使用一个使用语句流而不是调用关闭明确。)

Well it sounds like the data is just inappropriate, and that otherwise the code would work okay. (Admittedly I'd use a "using" statement for the streams instead of calling Close explicitly.)

在哪里你从获取数据的?

Where did you get your data from?

这篇关于如何使用ICSharpCode.ZipLib与流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆