TriLib SharpZipLib.Zip.ZipEntry - 无法访问 GetInputStream() 的关闭流 [英] TriLib SharpZipLib.Zip.ZipEntry - Cannot access a closed Stream for GetInputStream()

查看:53
本文介绍了TriLib SharpZipLib.Zip.ZipEntry - 无法访问 GetInputStream() 的关闭流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这是使用 Unity 2020.1.4f1 和 Trilib 2.0.9 模型加载器)

(This is using Unity 2020.1.4f1 with Trilib 2.0.9 Model Loader)

我正在尝试从 zipStream 中提取字节(在 Unity 中将 bytes[] 加载到 Texture2D.LoadImage() 中).你是怎么做到的?

I'm trying to extract the bytes from a zipStream (to load the bytes[] into a Texture2D.LoadImage() in Unity). How do you do this?

这是我尝试过的方法以及我遇到的错误:

Here's what I have tried and the error I am getting:

我收到错误消息:无法访问关闭的流".对于 Stream zipStream = zipFile.GetInputStream(e) 其中 eZipEntry 来自一个 ZipFile(由闭源 sdk 生成)

I'm getting the error: "Cannot access a closed Stream." for Stream zipStream = zipFile.GetInputStream(e) where e is a ZipEntry from a ZipFile (produced by a closed-source sdk)


 Stream zipStream = zipFile.GetInputStream(e); // error occurs here
 
      tex.LoadImage(ReadFully(zipStream));
      tex.Apply();
 

    public static byte[] ReadFully(Stream input)
    {
        byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }
    }

e 在循环中提取 - 如果这很重要

and e is extracted within a loop - if that matters

foreach (ZipEntry e in zipFile)
        {
            if (e.IsFile)
            { ... 


ObjectDisposedException: Cannot access a closed Stream.
System.IO.MemoryStream.Seek (System.Int64 offset, System.IO.SeekOrigin loc) (at <fb001e01371b4adca20013e0ac763896>:0)
ICSharpCode.SharpZipLib.Zip.ZipFile.TestLocalHeader (ICSharpCode.SharpZipLib.Zip.ZipEntry entry, ICSharpCode.SharpZipLib.Zip.ZipFile+HeaderTest tests) (at <1a5a474a643a454ba874ca384c215100>:0)
ICSharpCode.SharpZipLib.Zip.ZipFile.LocateEntry (ICSharpCode.SharpZipLib.Zip.ZipEntry entry) (at <1a5a474a643a454ba874ca384c215100>:0)
ICSharpCode.SharpZipLib.Zip.ZipFile.GetInputStrea

推荐答案

所以,我们在聊天中讨论了这个问题,ZipFile 的问题是,它不包含文件名和 Stream 在里面.这在技术上意味着,我们无法在 ZipFile 对象中获取单个文件的流.

So, we discussed the issue in chat and the problem with ZipFile was, it contained no File Name and no Stream in it. Which technically means, we cannot get stream of the individual files in the ZipFile object.

场景:他们使用 TriLib 并传递服务器上可用的 zip 文件的 URL.TriLib 所做的是,它获取文件和信息,在一个对象中解析它,并在完成后将该对象返回到一个方法中.

Scenario: They were using TriLib and passing the URL of the zip file that was available on a server. What TriLib did was, it fetched the file and information, parsed it in an object and returned the object into a method upon completion.

问题: ZipFile 对象不包含有关单个文件及其 Stream 的信息,也没有名称,因此 Name 属性变为 null.这意味着,我们无法对 ZipFile 对象执行任何操作.

The Problem: ZipFile object contained no information regarding the Individual Files and their Stream neither it had a name, so the Name property was coming null. Which means, we couldn't perform any operation on the ZipFile object.

解决方案:我们制作了一个自定义下载器并将文件下载到磁盘上,然后将下载的文件传递给 ZipFile 构造函数,通过使用这种方法,我们拥有了所有zip 文件中的信息.

Solution: We made a custom downloader and downloaded the file onto disk, then passed the downloaded file to the ZipFile constructor, by using this approach, we had all the information inside of a zip file.

这篇关于TriLib SharpZipLib.Zip.ZipEntry - 无法访问 GetInputStream() 的关闭流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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