This project is read-only.

How to extract a multi-part RAR archive

Nov 23, 2012 at 9:53 AM

Hi,

I'm having difficulties with extracting multi-part RAR archives.

Such archives named as .part1.rar, .part2.rar.

I'm extracting files from each archive part to MemoryStream and my application is ended without any confirmation at this line:

 foreach (var fileInfo in extractor.ArchiveFileData)

Here the error that I see in Output: 

The program '[31804] %ProgramName%.vshost.exe: Managed (v4.0.30319)' has exited with code -2147483645 (0x80000003).

Here's my extraction code:

using (MemoryStream msCompressed = new MemoryStream(fileContents))
{
    SevenZipExtractor extractor = new SevenZipExtractor(msCompressed);

    foreach (var fileInfo in extractor.ArchiveFileData)
    {
        if (!fileInfo.IsDirectory)
        {
            try
            {
                byte[] fileBytes = new byte[fileInfo.Size];
                using (MemoryStream fileStream = new MemoryStream(fileBytes))
                {
                    extractor.ExtractFile(fileInfo.Index, fileStream);
                }
                result.Add(new KeyValuePair<string, byte[]>(fileInfo.FileName, fileBytes));
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            
        }
    }
    extractor.Dispose();
}