From 69fc74e376d220c99a7483a0003ae4121c193829 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 30 May 2017 15:37:41 +0100 Subject: [PATCH 1/2] Per entry compression was being written out incorrectly on the central directory. Fix for that. --- .../Writers/Zip/ZipCentralDirectoryEntry.cs | 17 +++++++++++++---- src/SharpCompress/Writers/Zip/ZipWriter.cs | 15 +++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs index fd8f4ba4a..0f18e813f 100644 --- a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs +++ b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs @@ -9,18 +9,27 @@ namespace SharpCompress.Writers.Zip { internal class ZipCentralDirectoryEntry { - internal string FileName { get; set; } + private readonly ZipCompressionMethod compression; + private readonly string fileName; + + public ZipCentralDirectoryEntry(ZipCompressionMethod compression, string fileName, ulong headerOffset) + { + this.compression = compression; + this.fileName = fileName; + HeaderOffset = headerOffset; + } + internal DateTime? ModificationTime { get; set; } internal string Comment { get; set; } internal uint Crc { get; set; } - internal ulong HeaderOffset { get; set; } internal ulong Compressed { get; set; } internal ulong Decompressed { get; set; } internal ushort Zip64HeaderOffset { get; set; } + internal ulong HeaderOffset { get; } - internal uint Write(Stream outputStream, ZipCompressionMethod compression) + internal uint Write(Stream outputStream) { - byte[] encodedFilename = Encoding.UTF8.GetBytes(FileName); + byte[] encodedFilename = Encoding.UTF8.GetBytes(fileName); byte[] encodedComment = Encoding.UTF8.GetBytes(Comment); var zip64_stream = Compressed >= uint.MaxValue || Decompressed >= uint.MaxValue; diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index 1f5908b1e..b908df5e4 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -55,7 +55,7 @@ protected override void Dispose(bool isDisposing) ulong size = 0; foreach (ZipCentralDirectoryEntry entry in entries) { - size += entry.Write(OutputStream, ToZipCompressionMethod(compressionType)); + size += entry.Write(OutputStream); } WriteEndRecord(size); } @@ -108,16 +108,16 @@ public void Write(string entryPath, Stream source, ZipWriterEntryOptions zipWrit public Stream WriteToStream(string entryPath, ZipWriterEntryOptions options) { + var compression = ToZipCompressionMethod(options.CompressionType ?? compressionType); + entryPath = NormalizeFilename(entryPath); options.ModificationDateTime = options.ModificationDateTime ?? DateTime.Now; options.EntryComment = options.EntryComment ?? string.Empty; - var entry = new ZipCentralDirectoryEntry + var entry = new ZipCentralDirectoryEntry(compression, entryPath, (ulong)streamPosition) { Comment = options.EntryComment, - FileName = entryPath, - ModificationTime = options.ModificationDateTime, - HeaderOffset = (ulong)streamPosition - }; + ModificationTime = options.ModificationDateTime + }; // Use the archive default setting for zip64 and allow overrides var useZip64 = isZip64; @@ -126,8 +126,7 @@ public Stream WriteToStream(string entryPath, ZipWriterEntryOptions options) var headersize = (uint)WriteHeader(entryPath, options, entry, useZip64); streamPosition += headersize; - return new ZipWritingStream(this, OutputStream, entry, - ToZipCompressionMethod(options.CompressionType ?? compressionType), + return new ZipWritingStream(this, OutputStream, entry, compression, options.DeflateCompressionLevel ?? compressionLevel); } From 9270d7cabfc0f46efab67b2ada1925d1c64970c1 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 30 May 2017 16:04:55 +0100 Subject: [PATCH 2/2] Add cache for dotnet packages --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 44d18befe..9737ad208 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ dist: trusty language: csharp +cache: + directories: + - $HOME/.dotnet solution: SharpCompress.sln matrix: include: