mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-22 23:15:20 +00:00
Merge pull request #997 from adamhathcock/copilot/fix-ziparchive-linux-issue
Fix ArchiveFactory.Open double-wrapping causing "Cannot determine compressed stream type" on Linux
This commit is contained in:
@@ -20,7 +20,7 @@ public static class ArchiveFactory
|
||||
public static IArchive Open(Stream stream, ReaderOptions? readerOptions = null)
|
||||
{
|
||||
readerOptions ??= new ReaderOptions();
|
||||
stream = new SharpCompressStream(stream, bufferSize: readerOptions.BufferSize);
|
||||
stream = SharpCompressStream.Create(stream, bufferSize: readerOptions.BufferSize);
|
||||
return FindFactory<IArchiveFactory>(stream).Open(stream, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -622,4 +622,36 @@ public class ArchiveTests : ReaderTests
|
||||
VerifyFiles();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ArchiveFactory_Open_WithPreWrappedStream()
|
||||
{
|
||||
// Test that ArchiveFactory.Open works correctly with a stream that's already wrapped
|
||||
// This addresses the issue where ZIP files fail to open on Linux
|
||||
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.noEmptyDirs.zip");
|
||||
|
||||
// Open with a pre-wrapped stream
|
||||
using (var fileStream = File.OpenRead(testArchive))
|
||||
using (var wrappedStream = SharpCompressStream.Create(fileStream, bufferSize: 32768))
|
||||
using (var archive = ArchiveFactory.Open(wrappedStream))
|
||||
{
|
||||
Assert.Equal(ArchiveType.Zip, archive.Type);
|
||||
Assert.Equal(3, archive.Entries.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ArchiveFactory_Open_WithRawFileStream()
|
||||
{
|
||||
// Test that ArchiveFactory.Open works correctly with a raw FileStream
|
||||
// This is the common use case reported in the issue
|
||||
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.noEmptyDirs.zip");
|
||||
|
||||
using (var stream = File.OpenRead(testArchive))
|
||||
using (var archive = ArchiveFactory.Open(stream))
|
||||
{
|
||||
Assert.Equal(ArchiveType.Zip, archive.Type);
|
||||
Assert.Equal(3, archive.Entries.Count());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user