Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read a zip embedded in a zip #662

Open
SOHODeveloper opened this issue Sep 17, 2021 · 3 comments
Open

Cannot read a zip embedded in a zip #662

SOHODeveloper opened this issue Sep 17, 2021 · 3 comments
Labels
documentation zip Related to ZIP file format

Comments

@SOHODeveloper
Copy link

Steps to reproduce

1.Open a zipfile
2.loop over till find a ZipEntry that is a zip file.
3. Stream s = zipfile.GetInputStream(zipEntry)
4. newZipFile = new ZipFile(s);

Expected behavior

Should open and process (by your example at https://github.com/icsharpcode/SharpZipLib/wiki/Unpack-a-Zip%2C-including-embedded-zips%2C-and-re-pack-into-a-new-zip-or-memorystream)

Actual behavior

Exception that says the stream is not seekable. The stacktrace shows that the exception is right in the ZipFile constructor.

Version of SharpZipLib 1.3.2

Obtained from (only keep the relevant lines)

  • Package installed using NuGet
@piksel
Copy link
Member

piksel commented Sep 17, 2021

The example is using ZipFile from a ZipFile stream recursevly. This cannot be done from a ZipInputStream, since, like the error message says, it does not support seeking.

@SOHODeveloper
Copy link
Author

SOHODeveloper commented Sep 17, 2021

I am sorry, but I do not understand.
The example.

using(var zipStream = zipFile.GetInputStream(zipEntry))
            {
                // Extract Zips-within-zips
                if (entryFileName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    RecursiveExtractRebuild(outZipStream, zipStream);
                } 

I do not see how that is not what I am doing.

        using (Stream s = zipFile.GetInputStream(ze))
        {
          if (ze.IsFile)
          {
            switch (Path.GetExtension(ze.Name).ToUpper())
            {
            case ".FILESLACK":
              result.CountSkipped++;
              break;
            case ".TXT":
            case ".XML":
              if (ProcessFileEntry(s, ze))
                result.CountSkipped++;
              else
                result.CountFiles++;
              break;
            case ".ZIP":
              result.CountEmbedded++;
              using (ZipFile sub_zip = new ZipFile(s, true))
              {

The real question is how can I recursively open and decompress zips. I never need these to be actual files and I am parsing the contents directly from the stream and storing in a database.

@piksel
Copy link
Member

piksel commented Sep 17, 2021

Sorry, I misread your initial issue. The stream returned from ZipFile.GetInputStream is only seekable if it's not compressed. I'm not sure why there is an example that explicitly does this.

Perhaps it could be done by using ZipInputStream instead of ZipFile, but I have not tried it.

@piksel piksel added documentation zip Related to ZIP file format labels Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation zip Related to ZIP file format
Projects
None yet
Development

No branches or pull requests

2 participants