in src/ICSharpCode.SharpZipLib/Zip/ZipFormat.cs [388:517]
internal static int WriteEndEntry(Stream stream, ZipEntry entry, StringCodec stringCodec)
{
stream.WriteLEInt(ZipConstants.CentralHeaderSignature);
stream.WriteLEShort((entry.HostSystem << 8) | entry.VersionMadeBy);
stream.WriteLEShort(entry.Version);
stream.WriteLEShort(entry.Flags);
stream.WriteLEShort((short)entry.CompressionMethodForHeader);
stream.WriteLEInt((int)entry.DosTime);
stream.WriteLEInt((int)entry.Crc);
if (entry.IsZip64Forced() ||
(entry.CompressedSize >= uint.MaxValue))
{
stream.WriteLEInt(-1);
}
else
{
stream.WriteLEInt((int)entry.CompressedSize);
}
if (entry.IsZip64Forced() ||
(entry.Size >= uint.MaxValue))
{
stream.WriteLEInt(-1);
}
else
{
stream.WriteLEInt((int)entry.Size);
}
byte[] name = stringCodec.ZipOutputEncoding.GetBytes(entry.Name);
if (name.Length > 0xffff)
{
throw new ZipException("Name too long.");
}
var ed = new ZipExtraData(entry.ExtraData);
if (entry.CentralHeaderRequiresZip64)
{
ed.StartNewEntry();
if (entry.IsZip64Forced() ||
(entry.Size >= 0xffffffff))
{
ed.AddLeLong(entry.Size);
}
if (entry.IsZip64Forced() ||
(entry.CompressedSize >= 0xffffffff))
{
ed.AddLeLong(entry.CompressedSize);
}
if (entry.Offset >= 0xffffffff)
{
ed.AddLeLong(entry.Offset);
}
ed.AddNewEntry(1);
}
else
{
ed.Delete(1);
}
if (entry.AESKeySize > 0)
{
AddExtraDataAES(entry, ed);
}
byte[] extra = ed.GetEntryData();
byte[] entryComment = !(entry.Comment is null)
? stringCodec.ZipOutputEncoding.GetBytes(entry.Comment)
: Empty.Array<byte>();
if (entryComment.Length > 0xffff)
{
throw new ZipException("Comment too long.");
}
stream.WriteLEShort(name.Length);
stream.WriteLEShort(extra.Length);
stream.WriteLEShort(entryComment.Length);
stream.WriteLEShort(0); // disk number
stream.WriteLEShort(0); // internal file attributes
// external file attributes
if (entry.ExternalFileAttributes != -1)
{
stream.WriteLEInt(entry.ExternalFileAttributes);
}
else
{
if (entry.IsDirectory)
{ // mark entry as directory (from nikolam.AT.perfectinfo.com)
stream.WriteLEInt(16);
}
else
{
stream.WriteLEInt(0);
}
}
if (entry.Offset >= uint.MaxValue)
{
stream.WriteLEInt(-1);
}
else
{
stream.WriteLEInt((int)entry.Offset);
}
if (name.Length > 0)
{
stream.Write(name, 0, name.Length);
}
if (extra.Length > 0)
{
stream.Write(extra, 0, extra.Length);
}
if (entryComment.Length > 0)
{
stream.Write(entryComment, 0, entryComment.Length);
}
return ZipConstants.CentralHeaderBaseSize + name.Length + extra.Length + entryComment.Length;
}