2026-05-26 15:47:44 +01:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
2026-10-02 08:59:29 +01:00
|
|
|
using System.Threading;
|
|
|
|
|
using SharpCompress;
|
2026-05-26 15:47:44 +01:00
|
|
|
using SharpCompress.Archives;
|
|
|
|
|
using SharpCompress.Common;
|
|
|
|
|
using SharpCompress.Readers;
|
|
|
|
|
using SharpCompress.Writers;
|
|
|
|
|
|
|
|
|
|
var original = "SharpCompress AOT smoke test";
|
2026-10-02 08:59:29 +01:00
|
|
|
var client = new SharpCompressClient();
|
2026-05-26 15:47:44 +01:00
|
|
|
using var archiveStream = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
using (
|
2026-10-02 08:59:29 +01:00
|
|
|
var writer = client.OpenWriter(
|
2026-05-26 15:47:44 +01:00
|
|
|
archiveStream,
|
|
|
|
|
ArchiveType.Zip,
|
|
|
|
|
new WriterOptions(CompressionType.Deflate) { LeaveStreamOpen = true }
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
using var entryStream = new MemoryStream(Encoding.UTF8.GetBytes(original));
|
|
|
|
|
writer.Write("payload.txt", entryStream, DateTime.UtcNow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
archiveStream.Position = 0;
|
2026-10-02 08:59:29 +01:00
|
|
|
using (var reader = client.OpenReader(archiveStream, ReaderOptions.ForExternalStream))
|
2026-05-26 15:47:44 +01:00
|
|
|
{
|
|
|
|
|
if (!reader.MoveToNextEntry() || reader.Entry.IsDirectory)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Expected a file entry.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var extracted = new MemoryStream();
|
2026-10-02 08:59:29 +01:00
|
|
|
client.Extractor.ExtractToStream(reader, extracted);
|
2026-05-26 15:47:44 +01:00
|
|
|
var actual = Encoding.UTF8.GetString(extracted.ToArray());
|
|
|
|
|
if (!string.Equals(original, actual, StringComparison.Ordinal))
|
|
|
|
|
{
|
2026-10-02 08:59:29 +01:00
|
|
|
throw new InvalidOperationException("Client reader round-trip content mismatch.");
|
2026-05-26 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
archiveStream.Position = 0;
|
2026-10-02 08:59:29 +01:00
|
|
|
using (var archive = client.OpenArchive(archiveStream, ReaderOptions.ForExternalStream))
|
2026-05-26 15:47:44 +01:00
|
|
|
{
|
|
|
|
|
var entryCount = 0;
|
|
|
|
|
foreach (var entry in archive.Entries)
|
|
|
|
|
{
|
|
|
|
|
if (!entry.IsDirectory)
|
|
|
|
|
{
|
|
|
|
|
entryCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entryCount != 1)
|
|
|
|
|
{
|
2026-10-02 08:59:29 +01:00
|
|
|
throw new InvalidOperationException("Client archive did not see the expected entry.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
archiveStream.Position = 0;
|
|
|
|
|
var information = await client.Inspector.InspectArchiveAsync(
|
|
|
|
|
archiveStream,
|
|
|
|
|
cancellationToken: CancellationToken.None
|
|
|
|
|
);
|
|
|
|
|
if (information?.EntryCount != 1 || !archiveStream.CanRead || archiveStream.Position != 0)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Client inspection did not preserve the source.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await using (
|
|
|
|
|
var archive = await client.OpenAsyncArchive(
|
|
|
|
|
archiveStream,
|
|
|
|
|
cancellationToken: CancellationToken.None
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
await foreach (var entry in archive.EntriesAsync)
|
|
|
|
|
{
|
|
|
|
|
using var extracted = new MemoryStream();
|
|
|
|
|
await client.Extractor.ExtractToStreamAsync(
|
|
|
|
|
entry,
|
|
|
|
|
extracted,
|
|
|
|
|
cancellationToken: CancellationToken.None
|
|
|
|
|
);
|
|
|
|
|
if (Encoding.UTF8.GetString(extracted.ToArray()) != original)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Async client extraction content mismatch.");
|
|
|
|
|
}
|
2026-05-26 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("SharpCompress AOT smoke test passed.");
|