Skip to content

Commit

Permalink
Merge pull request #235 from dbaumber/Issue-230
Browse files Browse the repository at this point in the history
Issue #230: preserve the compression method when getting a compressed…
  • Loading branch information
adamhathcock authored May 23, 2017
2 parents 0f2d325 + 7d0acbc commit 7b81d18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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.

0 comments on commit 7b81d18

Please sign in to comment.