Files
sharpcompress/tests/SharpCompress.Test/ArchiveTests.cs

644 lines
20 KiB
C#
Raw Permalink Normal View History

using System;
2015-12-30 11:19:42 +00:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
2025-10-27 10:46:08 +00:00
using System.Threading.Tasks;
using AwesomeAssertions;
2016-09-26 11:49:49 +01:00
using SharpCompress.Archives;
2015-12-30 11:19:42 +00:00
using SharpCompress.Common;
using SharpCompress.Compressors.Xz;
using SharpCompress.Crypto;
using SharpCompress.IO;
using SharpCompress.Readers;
2026-01-07 15:01:04 +00:00
using SharpCompress.Test.Mocks;
using SharpCompress.Writers;
using SharpCompress.Writers.Zip;
2015-12-30 11:19:42 +00:00
using Xunit;
2022-12-20 15:06:44 +00:00
namespace SharpCompress.Test;
public class ArchiveTests : ReaderTests
2015-12-30 11:19:42 +00:00
{
2022-12-20 15:06:44 +00:00
protected void ArchiveGetParts(IEnumerable<string> testArchives)
2015-12-30 11:19:42 +00:00
{
2022-12-20 15:06:44 +00:00
var arcs = testArchives.Select(a => Path.Combine(TEST_ARCHIVES_PATH, a)).ToArray();
var found = ArchiveFactory.GetFileParts(arcs[0]).ToArray();
Assert.Equal(arcs.Length, found.Length);
for (var i = 0; i < arcs.Length; i++)
{
2022-12-20 15:06:44 +00:00
Assert.Equal(arcs[i], found[i]);
}
2022-12-20 15:06:44 +00:00
}
2022-12-20 15:06:44 +00:00
protected void ArchiveStreamReadExtractAll(string testArchive, CompressionType compression)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
ArchiveStreamReadExtractAll(new[] { testArchive }, compression);
}
2015-12-30 11:19:42 +00:00
2022-12-20 15:06:44 +00:00
protected void ArchiveStreamReadExtractAll(
IEnumerable<string> testArchives,
CompressionType compression
)
{
foreach (var path in testArchives)
2015-12-30 11:19:42 +00:00
{
using (var stream = SharpCompressStream.CreateNonDisposing(File.OpenRead(path)))
2015-12-30 11:19:42 +00:00
{
2022-12-20 15:06:44 +00:00
try
2015-12-30 11:19:42 +00:00
{
2026-01-15 11:41:30 +00:00
using var archive = ArchiveFactory.OpenArchive(stream);
2022-12-20 15:06:44 +00:00
Assert.True(archive.IsSolid);
using (var reader = archive.ExtractAllEntries())
2015-12-30 11:19:42 +00:00
{
2022-12-20 15:06:44 +00:00
UseReader(reader, compression);
2015-12-30 11:19:42 +00:00
}
2022-12-20 15:06:44 +00:00
VerifyFiles();
2015-12-30 11:19:42 +00:00
2022-12-20 15:06:44 +00:00
if (archive.Entries.First().CompressionType == CompressionType.Rar)
{
stream.ThrowOnDispose = false;
2022-12-20 15:06:44 +00:00
return;
2015-12-30 11:19:42 +00:00
}
2022-12-20 15:14:22 +00:00
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH);
}
2022-12-20 15:06:44 +00:00
stream.ThrowOnDispose = false;
}
2022-12-20 15:06:44 +00:00
catch (Exception)
2022-12-20 13:45:47 +00:00
{
2022-12-20 15:06:44 +00:00
// Otherwise this will hide the original exception.
stream.ThrowOnDispose = false;
2022-12-20 13:45:47 +00:00
throw;
}
}
VerifyFiles();
}
2022-12-20 15:06:44 +00:00
}
2026-01-16 11:44:12 +00:00
protected void ArchiveStreamRead(string testArchive, ReaderOptions? readerOptions = null)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
2026-01-16 13:19:41 +00:00
ArchiveStreamRead(
ArchiveFactory.FindFactory<IArchiveFactory>(testArchive),
2026-01-22 08:52:00 +00:00
Path.GetExtension(testArchive),
2026-01-16 13:19:41 +00:00
readerOptions,
testArchive
);
2026-01-16 11:44:12 +00:00
}
protected void ArchiveStreamRead(
IArchiveFactory archiveFactory,
string testArchive,
ReaderOptions? readerOptions = null
)
2022-12-20 15:06:44 +00:00
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
2026-01-22 09:05:26 +00:00
ArchiveStreamRead(
archiveFactory,
Path.GetExtension(testArchive),
readerOptions,
testArchive
);
2022-12-20 15:06:44 +00:00
}
2022-12-20 15:06:44 +00:00
protected void ArchiveStreamRead(
string extension,
2022-12-20 15:06:44 +00:00
ReaderOptions? readerOptions = null,
params string[] testArchives
2026-01-22 14:15:47 +00:00
)
{
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchives[0]);
2026-01-16 13:19:41 +00:00
ArchiveStreamRead(
2026-01-22 14:15:47 +00:00
ArchiveFactory.FindFactory<IArchiveFactory>(testArchive),
extension,
2026-01-16 13:19:41 +00:00
readerOptions,
testArchives
);
2026-01-22 14:15:47 +00:00
}
protected void ArchiveStreamRead(
IArchiveFactory archiveFactory,
string extension,
ReaderOptions? readerOptions = null,
params string[] testArchives
2022-12-20 15:20:49 +00:00
) =>
2022-12-20 15:06:44 +00:00
ArchiveStreamRead(
archiveFactory,
2022-12-20 15:06:44 +00:00
readerOptions,
testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x)),
extension
2022-12-20 15:06:44 +00:00
);
protected void ArchiveStreamRead(
IArchiveFactory archiveFactory,
ReaderOptions? readerOptions,
IEnumerable<string> testArchives,
string extension
)
2022-12-20 15:06:44 +00:00
{
2026-01-22 08:52:00 +00:00
ExtensionTest(extension, archiveFactory);
2022-12-20 15:06:44 +00:00
foreach (var path in testArchives)
{
using (var stream = SharpCompressStream.CreateNonDisposing(File.OpenRead(path)))
2026-01-15 11:41:30 +00:00
using (var archive = archiveFactory.OpenArchive(stream, readerOptions))
{
try
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH);
}
}
catch (IndexOutOfRangeException)
{
2022-12-20 15:06:44 +00:00
//SevenZipArchive_BZip2_Split test needs this
stream.ThrowOnDispose = false;
throw;
}
2022-12-20 15:06:44 +00:00
stream.ThrowOnDispose = false;
}
VerifyFiles();
}
2022-12-20 15:06:44 +00:00
}
2022-12-20 15:06:44 +00:00
protected void ArchiveStreamMultiRead(
ReaderOptions? readerOptions = null,
params string[] testArchives
2022-12-20 15:20:49 +00:00
) =>
2022-12-20 15:06:44 +00:00
ArchiveStreamMultiRead(
readerOptions,
testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))
);
2022-12-20 15:06:44 +00:00
protected void ArchiveStreamMultiRead(
ReaderOptions? readerOptions,
IEnumerable<string> testArchives
)
{
using (
2026-01-15 11:41:30 +00:00
var archive = ArchiveFactory.OpenArchive(
testArchives.Select(a => new FileInfo(a)).ToArray(),
2022-12-20 15:06:44 +00:00
readerOptions
)
2022-12-20 13:45:47 +00:00
)
{
2024-03-14 08:37:17 +00:00
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
2022-12-20 15:06:44 +00:00
{
entry.WriteToDirectory(SCRATCH_FILES_PATH);
2022-12-20 15:06:44 +00:00
}
}
2022-12-20 15:06:44 +00:00
VerifyFiles();
}
2022-12-20 15:06:44 +00:00
protected void ArchiveOpenStreamRead(
ReaderOptions? readerOptions = null,
params string[] testArchives
2022-12-20 15:20:49 +00:00
) =>
2022-12-20 15:06:44 +00:00
ArchiveOpenStreamRead(
readerOptions,
testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))
);
protected void ArchiveOpenStreamRead(
ReaderOptions? readerOptions,
IEnumerable<string> testArchives
)
{
using (
2026-01-15 11:41:30 +00:00
var archive = ArchiveFactory.OpenArchive(
testArchives.Select(f => new FileInfo(f)).ToArray(),
2022-12-20 15:06:44 +00:00
readerOptions
)
)
2015-12-30 11:19:42 +00:00
{
2024-03-14 08:37:17 +00:00
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
2022-12-20 15:06:44 +00:00
{
entry.WriteToDirectory(SCRATCH_FILES_PATH);
2022-12-20 15:06:44 +00:00
}
2015-12-30 11:19:42 +00:00
}
2022-12-20 15:06:44 +00:00
VerifyFiles();
}
2015-12-30 11:19:42 +00:00
2022-12-20 15:06:44 +00:00
protected void ArchiveOpenEntryVolumeIndexTest(
int[][] results,
ReaderOptions? readerOptions = null,
params string[] testArchives
2022-12-20 15:20:49 +00:00
) =>
2022-12-20 15:06:44 +00:00
ArchiveOpenEntryVolumeIndexTest(
results,
readerOptions,
testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))
);
2024-03-14 08:37:17 +00:00
private void ArchiveOpenEntryVolumeIndexTest(
2022-12-20 15:06:44 +00:00
int[][] results,
ReaderOptions? readerOptions,
IEnumerable<string> testArchives
)
{
var src = testArchives.ToArray();
2026-01-15 11:41:30 +00:00
using var archive = ArchiveFactory.OpenArchive(
src.Select(f => new FileInfo(f)).ToArray(),
2026-01-15 11:41:30 +00:00
readerOptions
);
2024-03-14 08:37:17 +00:00
var idx = 0;
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
2015-12-30 11:19:42 +00:00
{
2024-03-14 08:37:17 +00:00
Assert.Equal(entry.VolumeIndexFirst, results[idx][0]);
Assert.Equal(entry.VolumeIndexLast, results[idx][1]);
Assert.Equal(
src[entry.VolumeIndexFirst],
archive.Volumes.First(a => a.Index == entry.VolumeIndexFirst).FileName
);
Assert.Equal(
src[entry.VolumeIndexLast],
archive.Volumes.First(a => a.Index == entry.VolumeIndexLast).FileName
);
2022-12-20 15:06:44 +00:00
2024-03-14 08:37:17 +00:00
idx++;
2022-12-20 15:06:44 +00:00
}
}
protected void ArchiveExtractToDirectory(
string testArchive,
ReaderOptions? readerOptions = null
)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
2026-01-15 11:41:30 +00:00
using (var archive = ArchiveFactory.OpenArchive(new FileInfo(testArchive), readerOptions))
{
archive.WriteToDirectory(SCRATCH_FILES_PATH);
}
VerifyFiles();
}
protected void ArchiveFileRead(
string testArchive,
2026-01-16 11:44:12 +00:00
ReaderOptions? readerOptions = null,
2026-01-16 13:19:41 +00:00
IArchiveFactory? archiveFactory = null
)
2022-12-20 15:06:44 +00:00
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
2026-01-16 13:19:41 +00:00
archiveFactory ??= ArchiveFactory.FindFactory<IArchiveFactory>(testArchive);
2026-01-22 08:52:00 +00:00
ExtensionTest(testArchive, archiveFactory);
2026-01-15 11:41:30 +00:00
using (var archive = archiveFactory.OpenArchive(new FileInfo(testArchive), readerOptions))
2022-12-20 15:06:44 +00:00
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH);
2022-12-20 15:06:44 +00:00
}
}
VerifyFiles();
}
2026-01-22 08:52:00 +00:00
private void ExtensionTest(string fullPath, IArchiveFactory archiveFactory)
{
var extension = Path.GetExtension(fullPath).Substring(1);
if (!int.TryParse(extension, out _) && "exe" != extension) //exclude parts
{
extension.Should().BeOneOf(archiveFactory.GetSupportedExtensions());
}
}
2024-01-04 21:16:07 +01:00
protected void ArchiveFileSkip(
string testArchive,
string fileOrder,
ReaderOptions? readerOptions = null
)
{
2024-04-23 08:52:10 +01:00
if (!Environment.OSVersion.IsWindows())
2024-01-05 00:35:24 +01:00
{
fileOrder = fileOrder.Replace('\\', '/');
}
2024-01-04 21:16:07 +01:00
var expected = new Stack<string>(fileOrder.Split(' '));
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
2026-01-15 11:41:30 +00:00
using var archive = ArchiveFactory.OpenArchive(testArchive, readerOptions);
2024-03-14 08:37:17 +00:00
foreach (var entry in archive.Entries)
2024-01-04 21:16:07 +01:00
{
2024-03-14 08:37:17 +00:00
Assert.Equal(expected.Pop(), entry.Key);
2024-01-04 21:16:07 +01:00
}
}
2022-12-20 15:06:44 +00:00
/// <summary>
/// Demonstrate the ExtractionOptions.PreserveFileTime and ExtractionOptions.PreserveAttributes extract options
/// </summary>
protected void ArchiveFileReadEx(string testArchive)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
2026-01-15 11:41:30 +00:00
using (var archive = ArchiveFactory.OpenArchive(testArchive))
2022-12-20 15:06:44 +00:00
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH);
2015-12-30 11:19:42 +00:00
}
}
2022-12-20 15:06:44 +00:00
VerifyFilesEx();
2015-12-30 11:19:42 +00:00
}
2023-03-19 12:34:59 +01:00
protected void ArchiveDeltaDistanceRead(string testArchive)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
2026-01-15 11:41:30 +00:00
using var archive = ArchiveFactory.OpenArchive(testArchive);
2025-10-21 09:56:29 +01:00
foreach (var entry in archive.Entries)
2024-03-14 08:37:17 +00:00
{
2025-10-21 09:56:29 +01:00
if (!entry.IsDirectory)
2023-03-19 12:34:59 +01:00
{
2024-03-14 08:37:17 +00:00
var memory = new MemoryStream();
2025-10-21 09:56:29 +01:00
entry.WriteTo(memory);
2023-03-19 12:34:59 +01:00
2024-03-14 08:37:17 +00:00
memory.Position = 0;
2023-03-19 12:34:59 +01:00
2024-03-14 08:38:12 +00:00
for (var y = 0; y < 9; y++)
2024-03-14 08:37:17 +00:00
{
2026-01-23 10:55:51 +00:00
for (var x = 0; x < 256; x++)
{
Assert.Equal(x, memory.ReadByte());
}
2023-03-19 12:34:59 +01:00
}
2024-03-14 08:37:17 +00:00
Assert.Equal(-1, memory.ReadByte());
2023-03-19 12:34:59 +01:00
}
2024-03-14 08:37:17 +00:00
}
2023-03-19 12:34:59 +01:00
}
/// <summary>
/// Calculates CRC32 for the given data using SharpCompress implementation
/// </summary>
protected static uint CalculateCrc32(byte[] data) => Crc32.Compute(data);
/// <summary>
/// Creates a writer with the specified compression type and level
/// </summary>
2025-07-24 00:46:09 +01:00
protected static IWriter CreateWriterWithLevel(
Stream stream,
CompressionType compressionType,
int? compressionLevel = null
)
{
2026-02-06 15:16:45 +00:00
var writerOptions = compressionLevel.HasValue
? new WriterOptions(compressionType, compressionLevel.Value)
: new WriterOptions(compressionType);
2026-01-15 11:55:56 +00:00
return WriterFactory.OpenWriter(stream, ArchiveType.Zip, writerOptions);
}
2026-02-12 11:53:19 +00:00
protected static async ValueTask<IAsyncWriter> CreateWriterWithLevelAsync(
2026-01-13 13:54:15 +00:00
Stream stream,
CompressionType compressionType,
int? compressionLevel = null
)
{
2026-02-06 15:16:45 +00:00
var writerOptions = compressionLevel.HasValue
2026-02-10 11:10:04 +00:00
? new WriterOptions(compressionType, compressionLevel.Value) { LeaveStreamOpen = true }
2026-02-06 15:16:45 +00:00
: new WriterOptions(compressionType) { LeaveStreamOpen = true };
2026-02-12 11:53:19 +00:00
return await WriterFactory.OpenAsyncWriter(
2026-01-15 11:41:30 +00:00
new AsyncOnlyStream(stream),
ArchiveType.Zip,
writerOptions
);
2026-01-13 13:54:15 +00:00
}
/// <summary>
/// Verifies archive content against expected files with CRC32 validation
/// </summary>
2025-07-24 00:46:09 +01:00
protected void VerifyArchiveContent(
MemoryStream zipStream,
Dictionary<string, (byte[] data, uint crc)> expectedFiles
)
{
zipStream.Position = 0;
2026-01-15 11:41:30 +00:00
using var archive = ArchiveFactory.OpenArchive(zipStream);
Assert.Equal(expectedFiles.Count, archive.Entries.Count());
foreach (var entry in archive.Entries.Where(e => !e.IsDirectory))
{
using var entryStream = entry.OpenEntryStream();
using var extractedStream = new MemoryStream();
entryStream.CopyTo(extractedStream);
var extractedData = extractedStream.ToArray();
2025-07-24 00:46:09 +01:00
Assert.True(
expectedFiles.ContainsKey(entry.Key.NotNull()),
$"Unexpected entry: {entry.Key}"
);
var (expectedData, expectedCrc) = expectedFiles[entry.Key.NotNull()];
var actualCrc = CalculateCrc32(extractedData);
Assert.Equal(expectedCrc, actualCrc);
Assert.Equal(expectedData.Length, extractedData.Length);
2025-07-24 00:46:09 +01:00
// For large files, spot check rather than full comparison for performance
if (expectedData.Length > 1024 * 1024)
{
VerifyDataSpotCheck(expectedData, extractedData);
}
else
{
Assert.Equal(expectedData, extractedData);
}
}
}
/// <summary>
/// Performs efficient spot checks on large data arrays
/// </summary>
protected static void VerifyDataSpotCheck(byte[] expected, byte[] actual)
{
// Check first, middle, and last 1KB
Assert.Equal(expected.Take(1024), actual.Take(1024));
var mid = expected.Length / 2;
Assert.Equal(expected.Skip(mid).Take(1024), actual.Skip(mid).Take(1024));
2025-07-24 00:46:09 +01:00
Assert.Equal(
expected.Skip(Math.Max(0, expected.Length - 1024)),
actual.Skip(Math.Max(0, actual.Length - 1024))
);
}
/// <summary>
/// Verifies compression ratio meets expectations
/// </summary>
2025-07-24 00:46:09 +01:00
protected void VerifyCompressionRatio(
long originalSize,
long compressedSize,
double maxRatio,
string context
)
{
var compressionRatio = (double)compressedSize / originalSize;
2025-07-24 00:46:09 +01:00
Assert.True(
compressionRatio < maxRatio,
$"Expected better compression for {context}. Original: {originalSize}, Compressed: {compressedSize}, Ratio: {compressionRatio:P}"
);
}
/// <summary>
/// Creates a memory-based archive with specified files and compression
/// </summary>
2025-07-24 00:46:09 +01:00
protected MemoryStream CreateMemoryArchive(
Dictionary<string, byte[]> files,
CompressionType compressionType,
int? compressionLevel = null
)
{
var zipStream = new MemoryStream();
using (var writer = CreateWriterWithLevel(zipStream, compressionType, compressionLevel))
{
foreach (var kvp in files)
{
writer.Write(kvp.Key, new MemoryStream(kvp.Value));
}
}
return zipStream;
}
/// <summary>
/// Verifies streaming CRC calculation for large data
/// </summary>
protected void VerifyStreamingCrc(Stream entryStream, uint expectedCrc, long expectedLength)
{
using var crcStream = new Crc32Stream(Stream.Null);
const int bufferSize = 64 * 1024;
var buffer = new byte[bufferSize];
int totalBytesRead = 0;
int bytesRead;
while ((bytesRead = entryStream.Read(buffer, 0, bufferSize)) > 0)
{
crcStream.Write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
}
var actualCrc = crcStream.Crc;
Assert.Equal(expectedCrc, actualCrc);
Assert.Equal(expectedLength, totalBytesRead);
}
/// <summary>
/// Creates and verifies a basic archive with compression testing
/// </summary>
protected void CreateAndVerifyBasicArchive(
Dictionary<string, byte[]> testFiles,
CompressionType compressionType,
int? compressionLevel = null,
2025-07-24 00:46:09 +01:00
double maxCompressionRatio = 0.8
)
{
// Calculate expected CRCs
var expectedFiles = testFiles.ToDictionary(
kvp => kvp.Key,
kvp => (data: kvp.Value, crc: CalculateCrc32(kvp.Value))
);
// Create archive
using var zipStream = CreateMemoryArchive(testFiles, compressionType, compressionLevel);
// Verify compression occurred if expected
if (compressionType != CompressionType.None)
{
var originalSize = testFiles.Values.Sum(data => (long)data.Length);
2025-07-24 00:46:09 +01:00
VerifyCompressionRatio(
originalSize,
zipStream.Length,
maxCompressionRatio,
compressionType.ToString()
);
}
// Verify content
VerifyArchiveContent(zipStream, expectedFiles);
}
/// <summary>
/// Verifies archive entries have correct compression type
/// </summary>
2025-07-24 00:46:09 +01:00
protected void VerifyCompressionType(
MemoryStream zipStream,
CompressionType expectedCompressionType
)
{
zipStream.Position = 0;
2026-01-15 11:41:30 +00:00
using var archive = ArchiveFactory.OpenArchive(zipStream);
2025-07-24 00:46:09 +01:00
foreach (var entry in archive.Entries.Where(e => !e.IsDirectory))
{
Assert.Equal(expectedCompressionType, entry.CompressionType);
}
}
/// <summary>
/// Extracts and verifies a single entry from archive
/// </summary>
2025-07-24 00:46:09 +01:00
protected (byte[] data, uint crc) ExtractAndVerifyEntry(
MemoryStream zipStream,
string entryName
)
{
zipStream.Position = 0;
2026-01-15 11:41:30 +00:00
using var archive = ArchiveFactory.OpenArchive(zipStream);
2025-07-24 00:46:09 +01:00
var entry = archive.Entries.FirstOrDefault(e => e.Key == entryName && !e.IsDirectory);
Assert.NotNull(entry);
using var entryStream = entry.OpenEntryStream();
using var extractedStream = new MemoryStream();
entryStream.CopyTo(extractedStream);
2025-07-24 00:46:09 +01:00
var extractedData = extractedStream.ToArray();
var crc = CalculateCrc32(extractedData);
2025-07-24 00:46:09 +01:00
return (extractedData, crc);
}
2025-10-27 10:46:08 +00:00
protected async Task ArchiveStreamReadAsync(
string testArchive,
ReaderOptions? readerOptions = null
)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
await ArchiveStreamReadAsync(
2026-01-16 11:44:12 +00:00
ArchiveFactory.FindFactory<IArchiveFactory>(testArchive),
2025-10-27 10:46:08 +00:00
readerOptions,
new[] { testArchive }
);
}
protected async Task ArchiveStreamReadAsync(
IArchiveFactory archiveFactory,
ReaderOptions? readerOptions,
IEnumerable<string> testArchives
)
{
foreach (var path in testArchives)
{
using (var stream = SharpCompressStream.CreateNonDisposing(File.OpenRead(path)))
await using (
2026-02-12 10:26:18 +00:00
var archive = await archiveFactory.OpenAsyncArchive(
2026-01-15 11:41:30 +00:00
new AsyncOnlyStream(stream),
readerOptions
)
2026-01-07 16:38:48 +00:00
)
2025-10-27 10:46:08 +00:00
{
try
{
2026-01-08 09:41:48 +00:00
await foreach (
var entry in archive.EntriesAsync.Where(entry => !entry.IsDirectory)
)
2025-10-27 10:46:08 +00:00
{
await entry.WriteToDirectoryAsync(SCRATCH_FILES_PATH);
2025-10-27 10:46:08 +00:00
}
}
catch (IndexOutOfRangeException)
{
//SevenZipArchive_BZip2_Split test needs this
stream.ThrowOnDispose = false;
throw;
}
stream.ThrowOnDispose = false;
}
VerifyFiles();
}
}
2015-12-30 11:19:42 +00:00
}