mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-15 21:22:53 +00:00
Detect when users try to open tar.bz2, tar.lz, and other compressed tar formats with ArchiveFactory.Open() and provide clear guidance to use ReaderFactory.Open() instead. These formats require forward-only reading due to decompression stream limitations and cannot be used with the random-access Archive API. Includes tests to verify the helpful error messages are shown. Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using SharpCompress.Archives;
|
|
using Xunit;
|
|
|
|
namespace SharpCompress.Test;
|
|
|
|
public class ArchiveFactoryCompressedTarTests : TestBase
|
|
{
|
|
[Fact]
|
|
public void ArchiveFactory_Open_TarBz2_ThrowsHelpfulException()
|
|
{
|
|
var testFile = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.bz2");
|
|
var exception = Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
using var archive = ArchiveFactory.Open(testFile);
|
|
});
|
|
|
|
Assert.Contains("tar.bz2", exception.Message);
|
|
Assert.Contains("ReaderFactory", exception.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void ArchiveFactory_Open_TarLz_ThrowsHelpfulException()
|
|
{
|
|
var testFile = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.lz");
|
|
var exception = Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
using var archive = ArchiveFactory.Open(testFile);
|
|
});
|
|
|
|
Assert.Contains("tar.lz", exception.Message);
|
|
Assert.Contains("ReaderFactory", exception.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void ArchiveFactory_Open_TarBz2Stream_ThrowsHelpfulException()
|
|
{
|
|
var testFile = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.bz2");
|
|
using var stream = File.OpenRead(testFile);
|
|
var exception = Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
using var archive = ArchiveFactory.Open(stream);
|
|
});
|
|
|
|
Assert.Contains("tar.bz2", exception.Message);
|
|
Assert.Contains("ReaderFactory", exception.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void ArchiveFactory_Open_TarLzStream_ThrowsHelpfulException()
|
|
{
|
|
var testFile = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.lz");
|
|
using var stream = File.OpenRead(testFile);
|
|
var exception = Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
using var archive = ArchiveFactory.Open(stream);
|
|
});
|
|
|
|
Assert.Contains("tar.lz", exception.Message);
|
|
Assert.Contains("ReaderFactory", exception.Message);
|
|
}
|
|
}
|