diff --git a/RecursiveExtractor/Extractors/RarExtractor.cs b/RecursiveExtractor/Extractors/RarExtractor.cs index 1547245..7249ab6 100644 --- a/RecursiveExtractor/Extractors/RarExtractor.cs +++ b/RecursiveExtractor/Extractors/RarExtractor.cs @@ -143,86 +143,33 @@ public IEnumerable Extract(FileEntry fileEntry, ExtractorOptions opti if (rarArchive != null && fileEntry.EntryStatus == FileEntryStatus.Default) { var entries = rarArchive.Entries.Where(x => x.IsComplete && !x.IsDirectory); - if (options.Parallel) + foreach (var entry in entries) { - var files = new ConcurrentStack(); - - while (entries.Any()) + governor.CheckResourceGovernor(entry.Size); + FileEntry? newFileEntry = null; + try { - var batchSize = Math.Min(options.BatchSize, entries.Count()); - - var streams = entries.Take(batchSize).Select(entry => (entry, entry.OpenEntryStream())).ToList(); - - governor.CheckResourceGovernor(streams.Sum(x => x.Item2.Length)); - - streams.AsParallel().ForAll(streampair => - { - try - { - FileEntry newFileEntry = new FileEntry(streampair.entry.Key, streampair.Item2, fileEntry, false, streampair.entry.CreatedTime, streampair.entry.LastModifiedTime, streampair.entry.LastAccessedTime, memoryStreamCutoff: options.MemoryStreamCutoff); - - if (newFileEntry != null) - { - if (options.Recurse || topLevel) - { - var entries = Context.Extract(newFileEntry, options, governor, false); - if (entries.Any()) - { - files.PushRange(entries.ToArray()); - } - } - else - { - files.Push(newFileEntry); - } - } - } - catch (Exception e) - { - Logger.Debug(Extractor.DEBUG_STRING, ArchiveFileType.RAR, fileEntry.FullPath, streampair.entry.Key, e.GetType()); - } - }); - governor.CheckResourceGovernor(0); - - entries = entries.Skip(streams.Count); - - while (files.TryPop(out var result)) - { - if (result != null) - yield return result; - } + var stream = entry.OpenEntryStream(); + var name = entry.Key.Replace('/', Path.DirectorySeparatorChar); + newFileEntry = new FileEntry(name, stream, fileEntry, false, entry.CreatedTime, entry.LastModifiedTime, entry.LastAccessedTime, memoryStreamCutoff: options.MemoryStreamCutoff); } - } - else - { - foreach (var entry in entries) + catch (Exception e) { - governor.CheckResourceGovernor(entry.Size); - FileEntry? newFileEntry = null; - try - { - var stream = entry.OpenEntryStream(); - var name = entry.Key.Replace('/', Path.DirectorySeparatorChar); - newFileEntry = new FileEntry(name, stream, fileEntry, false, entry.CreatedTime, entry.LastModifiedTime, entry.LastAccessedTime, memoryStreamCutoff: options.MemoryStreamCutoff); - } - catch (Exception e) - { - Logger.Debug(Extractor.DEBUG_STRING, ArchiveFileType.RAR, fileEntry.FullPath, entry.Key, e.GetType()); - } - if (newFileEntry != null) + Logger.Debug(Extractor.DEBUG_STRING, ArchiveFileType.RAR, fileEntry.FullPath, entry.Key, e.GetType()); + } + if (newFileEntry != null) + { + if (options.Recurse || topLevel) { - if (options.Recurse || topLevel) - { - foreach (var innerEntry in Context.Extract(newFileEntry, options, governor, false)) - { - yield return innerEntry; - } - } - else + foreach (var innerEntry in Context.Extract(newFileEntry, options, governor, false)) { - yield return newFileEntry; + yield return innerEntry; } } + else + { + yield return newFileEntry; + } } } }