Skip to content

Commit

Permalink
Merge pull request #601 from salvois/master
Browse files Browse the repository at this point in the history
Write ZIP64 End of Central Directory only if needed.
  • Loading branch information
adamhathcock committed Jun 4, 2021
2 parents 8ee257d + c012db0 commit 161f99b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/SharpCompress/Writers/Zip/ZipWriter.cs
Expand Up @@ -238,13 +238,13 @@ private void WriteFooter(uint crc, uint compressed, uint uncompressed)
private void WriteEndRecord(ulong size)
{

var zip64 = isZip64 || entries.Count > ushort.MaxValue || streamPosition >= uint.MaxValue || size >= uint.MaxValue;
var zip64EndOfCentralDirectoryNeeded = entries.Count > ushort.MaxValue || streamPosition >= uint.MaxValue || size >= uint.MaxValue;

var sizevalue = size >= uint.MaxValue ? uint.MaxValue : (uint)size;
var streampositionvalue = streamPosition >= uint.MaxValue ? uint.MaxValue : (uint)streamPosition;

Span<byte> intBuf = stackalloc byte[8];
if (zip64)
if (zip64EndOfCentralDirectoryNeeded)
{
var recordlen = 2 + 2 + 4 + 4 + 8 + 8 + 8 + 8;

Expand Down Expand Up @@ -281,8 +281,7 @@ private void WriteEndRecord(ulong size)
BinaryPrimitives.WriteUInt32LittleEndian(intBuf, 1);
OutputStream.Write(intBuf.Slice(0, 4)); // Number of disks

streamPosition += recordlen + (4 + 4 + 8 + 4);
streampositionvalue = streamPosition >= uint.MaxValue ? uint.MaxValue : (uint)streampositionvalue;
streamPosition += 4 + 8 + recordlen + (4 + 4 + 8 + 4);
}

// Write normal end of central directory record
Expand Down

0 comments on commit 161f99b

Please sign in to comment.