C# SharpCompress - Can't open nested Archive with ArchiveFactory.Open

I am using SharpCompress to extract a large amount of archives that have nested archives inside of them. I need to be able to get the CRC of each file in the base archive and also the crc's for each file in the nested archives inside of the base archive. For performance reasons I need to do this while the zips are in memory such as a stream. (i.e. not extract them to the disk first, then process them.)

Example Zip Structure of "RootZip.zip"

RootZip.zip
RootZip.zip\SubFolderInZip\NestedZipLvl1.rar
RootZip.zip\SubFolderInZip\NestedZipLvl1.rar\SomeOtherSubFolder\NestedZipLvl2.7z

Each archive contains files in addition to the nested archives.

I need to be able to:

  1. Get the CRC for each file in "RootZip.zip", "SubZipLvl1.zip", and "SubZipLvl2.7z".
  2. Extract specific files from each zip ("RootZip.zip", "SubZipLvl1.zip", and "SubZipLvl2.7z")

What I have tried:

I have found that processing each zip through the ArchiveFactory and using the IArchive interface, I am able to get all the CRCs for the files in teh root zip using "archive.Entries[i].crc", but it will not allow me to open the entry stream for entry's that are nested archives using this method, so that I can get the CRCs for the files inside of them also (See code below):

private static HashSet<Zip> GetZipInfo(IArchive archive)
{
    HashSet<Zip> result = new HashSet<Zip>();
    HashSet<long> allCrc = new HashSet<long>();

    foreach (var entry in archive.Entries)
    {
        if (!entry.IsDirectory
            && PathLoc.HasRootFolder(entry.Key))
        {
            allCrc.Add(entry.Crc);
            //TODO: Extract File.
        }
        else if (!entry.IsDirectory
            && PathLoc.IsZip(entry.Key))
        {
            // If the entry is a subZip, then start extracting that zip
            using (IArchive newArchive = ArchiveFactory.Open(entry.OpenEntryStream()))
            {
                result.Union(GetZipInfo(archive));
            }
        }
    }
    return result;
}

The above code throws an exception "$exception {"Stream should be readable and seekable"}" which you would think makes sense, because I am trying to open a reader in a already open reader... BUT...

I am able to extract the contents of the nested archives, if I use this approach of nested readers using streams (Error handling was removed to reduce its size):

private ZipInfo RecursiveParseExample(Stream stream)
{
    using (var reader = ReaderFactory.Open(stream))
    {
        while (reader.MoveToNextEntry())
        {
            if (!reader.Entry.IsDirectory)
            {
                if (IsZip(reader.Entry))
                {
                    RecursiveParseExample(reader.OpenEntryStream());
                }
                else
                {
                    reader.WriteEntryTo(myPath);
                }
            }
        }
    }
}

I can extract the nested archives, but I can't find a way to get the CRCs from each file from the reader class.

How do I get the CRCs from the files in the nested zips, without having to extract them to the disk first?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum