Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #230: preserve the compression method when getting a compressed… #235

Merged
merged 4 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart part)

public virtual Stream OpenEntryStream()
{
return Parts.Single().GetCompressedStream();
var filePart = Parts.Single() as ZipFilePart;
var compressionMethod = filePart.Header.CompressionMethod;
var stream = filePart.GetCompressedStream();
if (filePart.Header.CompressionMethod != compressionMethod)
{
filePart.Header.CompressionMethod = compressionMethod;
}

return stream;
}

#region IArchiveEntry Members
Expand Down
18 changes: 18 additions & 0 deletions tests/SharpCompress.Test/Zip/ZipArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,24 @@ public void Zip_Deflate_WinzipAES_Read()
VerifyFiles();
}

[Fact]
public void Zip_Deflate_WinzipAES_MultiOpenEntryStream()
{
ResetScratch();
using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES2.zip"), new ReaderOptions()
{
Password = "test"
}))
{
foreach (var entry in reader.Entries.Where(x => !x.IsDirectory))
{
var stream = entry.OpenEntryStream();
Assert.NotNull(stream);
var ex = Record.Exception(() => stream = entry.OpenEntryStream());
Assert.Null(ex);
}
}
}

[Fact]
public void Zip_BZip2_Pkware_Read()
Expand Down
Binary file not shown.