Why would the SevenZipSharp.Interop NuGet extract more than one file when trying to extract a single file?

2020-02-15 c# 7zip sevenzipsharp

Maybe it's just me and I'm doing something really wrong or maybe this is the expected results of the class but I fell like something is wrong with it...

I have made the following test archive (there are also files in the folders but it shouldn't be relative to this question): enter image description here

I use the follow method to extract a single file (New Text Document.txt)...

#region SevenZipExtractor events
private void SevenZipExtractor_Extracting(object sender, ProgressEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("SevenZipExtractor_Extracting -- " + e.PercentDone + "%");

    m_progress.UpdateProcessingStatus(e.PercentDone);
}

private void SevenZipExtractor_FileExtractionFinished(object sender, FileInfoEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("SevenZipExtractor_FileExtractionFinished -- " + e.PercentDone + "% Filename:" + e.FileInfo.FileName);
}

private void SevenZipExtractor_FileExtractionStarted(object sender, FileInfoEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("SevenZipExtractor_FileExtractionStarted -- " + e.PercentDone + "% Filename:" + e.FileInfo.FileName);
}
#endregion

private void DecompressThread()
{
    using (SevenZipExtractor extractor = new SevenZipExtractor(inStream))
    {
        extractor.Extracting += SevenZipExtractor_Extracting;
        extractor.FileExtractionStarted += SevenZipExtractor_FileExtractionStarted;
        extractor.FileExtractionFinished += SevenZipExtractor_FileExtractionFinished;

        using (FileStream file = new FileStream("C:\Sandbox\Z-Test\New Text Document.txt", FileMode.Create, FileAccess.Write))
        {
            extractor.ExtractFile(4, file);
        }

        extractor.Extracting -= SevenZipExtractor_Extracting;
        extractor.FileExtractionStarted -= SevenZipExtractor_FileExtractionStarted;
        extractor.FileExtractionFinished -= SevenZipExtractor_FileExtractionFinished;
    }
}

Then with the events Extracting, FileExtractionStarted and FileExtractionFinished I would EXPECT to get back the following results...

SevenZipExtractor_FileExtractionStarted -- 100% Filename:New Text Document.txt
SevenZipExtractor_Extracting -- 100%
SevenZipExtractor_FileExtractionFinished -- 100% Filename:New Text Document.txt

However, I get back the following results...

SevenZipExtractor_Extracting -- 100%
SevenZipExtractor_Extracting -- 100%
SevenZipExtractor_FileExtractionStarted -- 20% Filename:Test Folder 1
SevenZipExtractor_FileExtractionFinished -- 20% Filename:Test Folder 1
SevenZipExtractor_FileExtractionStarted -- 40% Filename:Test Folder 2
SevenZipExtractor_FileExtractionFinished -- 40% Filename:Test Folder 2
SevenZipExtractor_FileExtractionStarted -- 60% Filename:Microsoft - Visual Studio 6 MSDN Library.iso
SevenZipExtractor_Extracting -- 1%
SevenZipExtractor_Extracting -- 2%
SevenZipExtractor_Extracting -- 3%
SevenZipExtractor_Extracting -- 4%
SevenZipExtractor_Extracting -- 5%
SevenZipExtractor_Extracting -- 6%
SevenZipExtractor_Extracting -- 7%
SevenZipExtractor_Extracting -- 8%
SevenZipExtractor_Extracting -- 9%
SevenZipExtractor_Extracting -- 10%
SevenZipExtractor_Extracting -- 11%
SevenZipExtractor_Extracting -- 12%
SevenZipExtractor_Extracting -- 13%
SevenZipExtractor_Extracting -- 14%
SevenZipExtractor_Extracting -- 15%
SevenZipExtractor_Extracting -- 16%
SevenZipExtractor_Extracting -- 17%
SevenZipExtractor_Extracting -- 18%
SevenZipExtractor_Extracting -- 19%
SevenZipExtractor_Extracting -- 20%
SevenZipExtractor_Extracting -- 21%
SevenZipExtractor_Extracting -- 22%
SevenZipExtractor_Extracting -- 23%
SevenZipExtractor_Extracting -- 24%
SevenZipExtractor_Extracting -- 25%
SevenZipExtractor_Extracting -- 26%
SevenZipExtractor_Extracting -- 27%
SevenZipExtractor_Extracting -- 28%
SevenZipExtractor_Extracting -- 29%
SevenZipExtractor_Extracting -- 30%
SevenZipExtractor_Extracting -- 31%
SevenZipExtractor_Extracting -- 32%
SevenZipExtractor_Extracting -- 33%
SevenZipExtractor_Extracting -- 34%
SevenZipExtractor_Extracting -- 35%
SevenZipExtractor_Extracting -- 36%
SevenZipExtractor_Extracting -- 37%
SevenZipExtractor_Extracting -- 38%
SevenZipExtractor_Extracting -- 39%
SevenZipExtractor_Extracting -- 40%
SevenZipExtractor_Extracting -- 41%
SevenZipExtractor_Extracting -- 42%
SevenZipExtractor_Extracting -- 43%
SevenZipExtractor_Extracting -- 44%
SevenZipExtractor_Extracting -- 45%
SevenZipExtractor_Extracting -- 46%
SevenZipExtractor_Extracting -- 47%
SevenZipExtractor_Extracting -- 48%
SevenZipExtractor_Extracting -- 49%
SevenZipExtractor_Extracting -- 50%
SevenZipExtractor_Extracting -- 51%
SevenZipExtractor_Extracting -- 52%
SevenZipExtractor_Extracting -- 53%
SevenZipExtractor_Extracting -- 54%
SevenZipExtractor_Extracting -- 55%
SevenZipExtractor_Extracting -- 56%
SevenZipExtractor_Extracting -- 57%
SevenZipExtractor_Extracting -- 58%
SevenZipExtractor_Extracting -- 59%
SevenZipExtractor_Extracting -- 60%
SevenZipExtractor_Extracting -- 61%
SevenZipExtractor_Extracting -- 62%
SevenZipExtractor_Extracting -- 63%
SevenZipExtractor_Extracting -- 64%
SevenZipExtractor_Extracting -- 65%
SevenZipExtractor_Extracting -- 66%
SevenZipExtractor_Extracting -- 67%
SevenZipExtractor_Extracting -- 68%
SevenZipExtractor_Extracting -- 69%
SevenZipExtractor_Extracting -- 70%
SevenZipExtractor_Extracting -- 71%
SevenZipExtractor_Extracting -- 72%
SevenZipExtractor_Extracting -- 73%
SevenZipExtractor_Extracting -- 74%
SevenZipExtractor_Extracting -- 75%
SevenZipExtractor_Extracting -- 76%
SevenZipExtractor_Extracting -- 77%
SevenZipExtractor_Extracting -- 78%
SevenZipExtractor_Extracting -- 79%
SevenZipExtractor_Extracting -- 80%
SevenZipExtractor_Extracting -- 81%
SevenZipExtractor_Extracting -- 82%
SevenZipExtractor_Extracting -- 83%
SevenZipExtractor_Extracting -- 84%
SevenZipExtractor_Extracting -- 85%
SevenZipExtractor_Extracting -- 86%
SevenZipExtractor_Extracting -- 87%
SevenZipExtractor_Extracting -- 88%
SevenZipExtractor_Extracting -- 89%
SevenZipExtractor_Extracting -- 90%
SevenZipExtractor_Extracting -- 91%
SevenZipExtractor_Extracting -- 92%
SevenZipExtractor_Extracting -- 93%
SevenZipExtractor_Extracting -- 94%
SevenZipExtractor_Extracting -- 95%
SevenZipExtractor_Extracting -- 96%
SevenZipExtractor_Extracting -- 97%
SevenZipExtractor_Extracting -- 98%
SevenZipExtractor_Extracting -- 99%
SevenZipExtractor_FileExtractionFinished -- 60% Filename:Microsoft - Visual Studio 6 MSDN Library.iso
SevenZipExtractor_FileExtractionStarted -- 80% Filename:New Microsoft Excel Worksheet.xlsx
SevenZipExtractor_FileExtractionFinished -- 80% Filename:New Microsoft Excel Worksheet.xlsx
SevenZipExtractor_FileExtractionStarted -- 100% Filename:New Text Document.txt
SevenZipExtractor_Extracting -- 100%
SevenZipExtractor_FileExtractionFinished -- 100% Filename:New Text Document.txt

It seems that even though I'm trying to extract a single file it is processing all the files up to that point. When I try to use this on a larger scale (extracting a whole file rather than just 1 single file) I'll have an archive with one big file in the root and a bunch of small files folders and see a huge impact when it tries to process each small file (it takes just as long to extract each small file as it does the large file at the root of the archive.

Is there some type of expectation for the user to set a seek point in a memory stream or something? How can I make it not take so long to extract a small text file?

Answers

Related