(This is using Unity 2020.1.4f1 with Trilib 2.0.9 Model Loader)
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:
I'm getting the error: "Cannot access a closed Stream." for
Stream zipStream = zipFile.GetInputStream(e)
wheree
is aZipEntry
from aZipFile
(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();
}
}
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