mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
Add tests for compressed TAR detection and fix stream disposal
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
This commit is contained in:
@@ -54,7 +54,7 @@ public class TarArchive : AbstractWritableArchive<TarArchiveEntry, TarVolume>
|
||||
{
|
||||
// Open the file to check for compression
|
||||
using var testStream = fileInfo.OpenRead();
|
||||
var rewindableStream = SharpCompressStream.Create(testStream, leaveOpen: false);
|
||||
using var rewindableStream = SharpCompressStream.Create(testStream, leaveOpen: false);
|
||||
var streamStack = (IStreamStack)rewindableStream;
|
||||
var startPos = streamStack.GetPosition();
|
||||
|
||||
|
||||
@@ -295,4 +295,47 @@ public class TarArchiveTests : ArchiveTests
|
||||
|
||||
Assert.False(isTar);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TarArchive_Open_Compressed_XZ_Throws()
|
||||
{
|
||||
var exception = Assert.Throws<InvalidFormatException>(() =>
|
||||
TarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.xz"))
|
||||
);
|
||||
|
||||
Assert.Contains("XZ", exception.Message);
|
||||
Assert.Contains("TarReader.Open", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TarArchive_Open_Compressed_GZip_Throws()
|
||||
{
|
||||
var exception = Assert.Throws<InvalidFormatException>(() =>
|
||||
TarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz"))
|
||||
);
|
||||
|
||||
Assert.Contains("GZip", exception.Message);
|
||||
Assert.Contains("TarReader.Open", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TarArchive_Open_Compressed_BZip2_Throws()
|
||||
{
|
||||
var exception = Assert.Throws<InvalidFormatException>(() =>
|
||||
TarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.bz2"))
|
||||
);
|
||||
|
||||
Assert.Contains("BZip2", exception.Message);
|
||||
Assert.Contains("TarReader.Open", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TarArchive_Open_Compressed_Stream_XZ_Throws()
|
||||
{
|
||||
using var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.xz"));
|
||||
var exception = Assert.Throws<InvalidFormatException>(() => TarArchive.Open(stream));
|
||||
|
||||
Assert.Contains("XZ", exception.Message);
|
||||
Assert.Contains("TarReader.Open", exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user