icsharpcode/SharpZipLib

InflaterInputStream Length is not supported The unsupported member type is located on type 'System.Int64'. Path: $.Length.

enti333 opened this issue · 3 comments

Steps to reproduce

After Migration from azure function .net framework to Azure Function Asp 6 unzipping stops working.
I have a simple code:

ZipFile zf = new ZipFile(fileStream);
zf.Password = zipPassword;

foreach (ZipEntry entry in zf)
{
    if (entry.IsFile)
    {
        Console.WriteLine("Extracting {0}", entry.Name);
        log.LogInformation("Extracting {0}", entry.Name);

        Stream stream = zf.GetInputStream(entry);
        byte[] byteS = stream.ToByteArray();

When I try to work with this stream I get the error:
InflaterInputStream Length is not supported The unsupported member type is located on type 'System.Int64'. Path: $.Length.

On the last row of code...Or if I try to upload a stream somewhere I still get the same error.
InflaterInputStream Length is not supported

I do not know what to do whit this because the same code was working on .net framework.
Thank you for your help.

Expected behavior

Getting the file stream from zipped file

Actual behavior

Exception

Version of SharpZipLib

Latest

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

I don't know ToByteArray does, but if you really want the entry contents as a byte buffer you could do:

var ms = new MemoryStream(entry.Size);
zf.GetInputStream.CopyTo(ms);
var bytes = ms.ToArray();

The InflaterInputStream does not know what it's final size will be until all data is read.

This is a bug. Uncompressed size is available in entry.Size, so why isn't it available in Stream.Length?

It's not a bug. Even though the information is available in the entry, the stream itself doesn't know and does not support seeking. Since the stream does not have the same number bytes read for the same number of bytes written, the concept of Length is confusing at best and is therefore avoided.