0

I am building an app to extract from tar and rar archives. I can report progress from target based on the amount of rar containing in the target and as each one is extracted. In the rars there is one file spanning several volumes. I have used the code off the unit tests examples

 var streams = testArchives.Select(s => Path.Combine(SCRATCH2_FILES_PATH, s)).Select(File.OpenRead).ToList();
 using (var reader = RarReader.Open(streams))
 {
     while (reader.MoveToNextEntry())
    {
         reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions()
         {
           ExtractFullPath = true,
           Overwrite = true
         });
    }
 }

The problem is that the process does not report until the current entry has extracted.

Aryan Firouzian
  • 1,940
  • 5
  • 27
  • 41

1 Answers1

-1

Don't use WriteEntryToDirectory to save the files, because it doesn't contain callback progress, instead of that, use FileStream and then get the full size of the uncompressed file and slice the save progress ok?

Here is a simple example:

thread = new Thread(
            new ThreadStart(() =>
            {
                using (Archive = RarArchive.Open(streams, new ReaderOptions() { Password = password, LookForHeader = true }))
                {
                    Archive.EntryExtractionBegin += EntryExtractionBeginEvet;
                    Archive.CompressedBytesRead += CompressedBytesReadEvent;
                    FilesTotalCount = Archive.Entries.Count();
                    TotalSize = Archive.TotalSize;
                    foreach (IArchiveEntry ArchiveEntry in Archive.Entries.Where(entry => !entry.IsDirectory))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(@"" + path + "\\" + ArchiveEntry.Key));
                        using (Stream archiveStream = ArchiveEntry.OpenEntryStream())
                        using (FileStream fileStream = new FileStream(@"" + path + "\\" + ArchiveEntry.Key, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
                        {
                            int byteSizes = 0;
                            byte[] buffer = new byte[bufferLenght];
                            while (ThreadState == ThreadState.Running && (byteSizes = archiveStream.Read(buffer, 0, buffer.Length)) > 0)
                                fileStream.Write(buffer, 0, byteSizes);
                        }
                    }
                }
                IO.CloseStreams(streams);
            }
        ));
        thread.Start();
Renan Araújo
  • 3,533
  • 11
  • 39
  • 49
user9022531
  • 107
  • 1
  • 2