icsharpcode / SharpZipLib

#ziplib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.
http://icsharpcode.github.io/SharpZipLib/
MIT License
3.73k stars 976 forks source link

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

Closed enti333 closed 1 year ago

enti333 commented 2 years ago

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)

piksel commented 2 years ago

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.

arnileibovits commented 1 year ago

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

piksel commented 1 year ago

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.