From 12a6d3977e548c3ccdf280ec6a88215552819e25 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Fri, 14 Dec 2018 22:44:44 +0000 Subject: [PATCH 1/2] Return the DirectoryEndHeader from SeekableZipHeaderFactory.ReadSeekable so that it can be used by ZipArchive --- .../Common/Zip/SeekableZipHeaderFactory.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs index 897b5a0a..23f4cbe8 100644 --- a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs @@ -17,7 +17,7 @@ namespace SharpCompress.Common.Zip { } - internal IEnumerable ReadSeekableHeader(Stream stream) + internal IEnumerable ReadSeekableHeader(Stream stream) { var reader = new BinaryReader(stream); @@ -51,16 +51,22 @@ namespace SharpCompress.Common.Zip { stream.Position = position; uint signature = reader.ReadUInt32(); - var directoryEntryHeader = ReadHeader(signature, reader, _zip64) as DirectoryEntryHeader; + var nextHeader = ReadHeader(signature, reader, _zip64); position = stream.Position; - if (directoryEntryHeader == null) - { - yield break; - } - //entry could be zero bytes so we need to know that. - directoryEntryHeader.HasData = directoryEntryHeader.CompressedSize != 0; - yield return directoryEntryHeader; + if (nextHeader == null) + yield break; + + if (nextHeader is DirectoryEntryHeader entryHeader) + { + //entry could be zero bytes so we need to know that. + entryHeader.HasData = entryHeader.CompressedSize != 0; + yield return entryHeader; + } + else if (nextHeader is DirectoryEndHeader endHeader) + { + yield return endHeader; + } } } From 4e9cd064dd120354eab19c031554ae5e40969a29 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 13 Jan 2019 21:05:55 +0000 Subject: [PATCH 2/2] Unit test to show reading of a Zip volume/archive comment --- tests/SharpCompress.Test/Zip/ZipArchiveTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs index 2d28767a..2576f253 100644 --- a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs @@ -357,6 +357,22 @@ namespace SharpCompress.Test.Zip } } + [Fact] + public void Zip_Read_Volume_Comment() + { + using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.zip64.zip"), new ReaderOptions() + { + Password = "test" + })) + { + var isComplete = reader.IsComplete; + Assert.Equal(1, reader.Volumes.Count); + + string expectedComment = "Encoding:utf-8 || Compression:Deflate levelDefault || Encrypt:None || ZIP64:Always\r\nCreated at 2017-Jan-23 14:10:43 || DotNetZip Tool v1.9.1.8\r\nTest zip64 archive"; + Assert.Equal(expectedComment, reader.Volumes.First().Comment); + } + } + [Fact] public void Zip_BZip2_Pkware_Read() {