Cannot read a zip embedded in a zip
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
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.
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.
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.