Files
sharpcompress/tests/SharpCompress.Test/ExtractAll.cs
copilot-swe-agent[bot] 93504cf82f Add sync test and attempt to fix async LZMA extraction bug
- Restored original async ExtractAllEntries test with using statement
- Added new ExtractAllEntriesSync test (all tests pass)
- Fixed potential partial read bug in LzmaStream.DecodeChunkHeaderAsync
  - Added ReadFullyAsync helper to ensure complete reads
  - ReadAsync is not guaranteed to return all requested bytes
- Async tests for 7Zip still failing with Data Error
  - Issue appears related to LZMA2 stream state management
  - _needDictReset flag not being cleared correctly in async flow
  - Further investigation needed

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
2025-12-19 12:15:54 +00:00

77 lines
2.3 KiB
C#

using System.IO;
using System.Linq;
using System.Threading.Tasks;
using SharpCompress.Archives;
using SharpCompress.Common;
using SharpCompress.Readers;
using Xunit;
namespace SharpCompress.Test;
public class ExtractAll : TestBase
{
[Theory]
[InlineData("Zip.deflate.zip")]
[InlineData("Rar5.rar")]
[InlineData("Rar.rar")]
[InlineData("Rar.solid.rar")]
[InlineData("7Zip.solid.7z")]
[InlineData("7Zip.nonsolid.7z")]
[InlineData("7Zip.LZMA.7z")]
public async Task ExtractAllEntries(string archivePath)
{
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, archivePath);
var options = new ExtractionOptions() { ExtractFullPath = true, Overwrite = true };
using var archive = ArchiveFactory.Open(testArchive);
if (archive.IsSolid || archive.Type == ArchiveType.SevenZip)
{
using var reader = archive.ExtractAllEntries();
while (await reader.MoveToNextEntryAsync())
{
if (!reader.Entry.IsDirectory)
{
await reader.WriteEntryToDirectoryAsync(SCRATCH_FILES_PATH, options);
}
}
}
else
{
archive.ExtractToDirectory(SCRATCH_FILES_PATH, options);
}
}
[Theory]
[InlineData("Zip.deflate.zip")]
[InlineData("Rar5.rar")]
[InlineData("Rar.rar")]
[InlineData("Rar.solid.rar")]
[InlineData("7Zip.solid.7z")]
[InlineData("7Zip.nonsolid.7z")]
[InlineData("7Zip.LZMA.7z")]
public void ExtractAllEntriesSync(string archivePath)
{
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, archivePath);
var options = new ExtractionOptions() { ExtractFullPath = true, Overwrite = true };
using var archive = ArchiveFactory.Open(testArchive);
if (archive.IsSolid || archive.Type == ArchiveType.SevenZip)
{
using var reader = archive.ExtractAllEntries();
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, options);
}
}
}
else
{
archive.ExtractToDirectory(SCRATCH_FILES_PATH, options);
}
}
}