SharpCompress/tests/SharpCompress.Test/WriterTests.cs

52 lines
1.6 KiB
C#
Raw Permalink Normal View History

2022-06-19 22:05:52 +02:00
using System.IO;
using System.Text;
2015-12-30 11:19:42 +00:00
using SharpCompress.Common;
using SharpCompress.IO;
2016-09-26 11:49:49 +01:00
using SharpCompress.Readers;
using SharpCompress.Writers;
2015-12-30 11:19:42 +00:00
2022-12-20 15:06:44 +00:00
namespace SharpCompress.Test;
public class WriterTests : TestBase
2015-12-30 11:19:42 +00:00
{
2022-12-20 15:06:44 +00:00
private readonly ArchiveType type;
2015-12-30 11:19:42 +00:00
2022-12-20 15:20:49 +00:00
protected WriterTests(ArchiveType type) => this.type = type;
2015-12-30 11:19:42 +00:00
2022-12-20 15:06:44 +00:00
protected void Write(
CompressionType compressionType,
string archive,
string archiveToVerifyAgainst,
Encoding? encoding = null
)
{
using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive)))
2015-12-30 11:19:42 +00:00
{
2022-12-20 15:14:22 +00:00
var writerOptions = new WriterOptions(compressionType) { LeaveStreamOpen = true, };
2020-07-26 14:36:07 +01:00
2022-12-20 15:06:44 +00:00
writerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;
2021-01-09 13:33:34 +00:00
2022-12-20 15:06:44 +00:00
using var writer = WriterFactory.Open(stream, type, writerOptions);
writer.WriteAll(ORIGINAL_FILES_PATH, "*", SearchOption.AllDirectories);
}
CompareArchivesByPath(
Path.Combine(SCRATCH2_FILES_PATH, archive),
Path.Combine(TEST_ARCHIVES_PATH, archiveToVerifyAgainst)
);
2015-12-30 11:19:42 +00:00
2022-12-20 15:06:44 +00:00
using (Stream stream = File.OpenRead(Path.Combine(SCRATCH2_FILES_PATH, archive)))
{
var readerOptions = new ReaderOptions();
2020-07-26 14:36:07 +01:00
2022-12-20 15:06:44 +00:00
readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;
2021-01-09 13:33:34 +00:00
2022-12-20 15:14:22 +00:00
using var reader = ReaderFactory.Open(NonDisposingStream.Create(stream), readerOptions);
2022-12-20 15:06:44 +00:00
reader.WriteAllToDirectory(
SCRATCH_FILES_PATH,
new ExtractionOptions() { ExtractFullPath = true }
);
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
}
}