4 Replies Latest reply: Apr 10, 2008 9:24 AM by 807591 RSS

    How to unzip a zip file within another zip file

    807591
      I've got code that successfully processes a file within a zip file.
      But now the zip file can also contain other zip files. How can I
      process a zip nested within a zip without actually extracting the
      files? It looks like I need a ZipFile object to be able to take
      advantage of the zip classes for reading zip entries. But the
      ZipFile methods want as an argument an actual file, as opposed
      to some object in memory. I can read the 'inner' zip file into a
      ZipInputStream object, but then how do I make that available for
      processing as a ZipFile? I've searched all over and cannot find
      anything anywhere that talks about working with nested zip files.
      Does anyone have any sample code that does this? Thanks!
        • 1. Re: How to unzip a zip file within another zip file
          807591
          I have successfully done it.

          You cannot have the code - it is proprietary.

          However here are a few pointers:

          o Use ZipStreams rather than ZipFile.

          o ZipStream is just a filter on a stream, so you can have a zipstream open, read a ZipEntry, then ask for a substream for the stuff up to the next ZipEntry. Put a second ZipStream on that substream.

          o As I recall you have to watch out that your inner ZipStream does not do a close. (Everything will get closed.) Instead, there is another ZipStream method that will close without closing all the underlying streams.

          Hope this helps.
          • 2. Re: How to unzip a zip file within another zip file
            DrClap
            Software can't get a list of the ZipEntries without being able to read the catalog of the zip file. And that catalog is stored at the end of the zip file, so it needs random access to the zip file to do that. And you can't have random access to a compressed file, you have to decompress it first.

            That's why you don't find anything about how to work with nested zip files. Because you can't.
            • 3. Re: How to unzip a zip file within another zip file
              807591
              OK, I've got it mostly working, but how do you get a stream
              if you don't have a file object?? I can say zipFile.getInputStream
              but I can't say zipInputStream.getInputStream, which could give
              me a stream from within the bigger stream. I cannot find methods
              for either ZipEntry or ZipInputStream that allow me to do this... I
              was trying to do a read but that results in a file with errors, most
              likely because I am not reading starting at the correct location in
              the stream.
              • 4. Re: How to unzip a zip file within another zip file
                807591
                Hi,

                Were you able to get this to work ?

                If yes, would it be possible to publish the code ?

                I'm struggling with the same problem and its driving me insane :-)

                Kind regards,
                Edh