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

Per entry compression was being written out incorrectly on the centra… #249

Merged
merged 4 commits into from
May 31, 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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
dist: trusty
language: csharp
cache:
directories:
- $HOME/.dotnet
solution: SharpCompress.sln
matrix:
include:
Expand Down
17 changes: 13 additions & 4 deletions src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 7 additions & 8 deletions src/SharpCompress/Writers/Zip/ZipWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down