in src/ICSharpCode.SharpZipLib/Zip/ZipFormat.cs [236:310]
public static async Task WriteEndOfCentralDirectoryAsync(Stream stream, long noOfEntries, long sizeEntries,
long start, byte[] comment, CancellationToken cancellationToken)
=> await stream.WriteProcToStreamAsync(s
=> WriteEndOfCentralDirectory(s, noOfEntries, sizeEntries, start, comment), cancellationToken);
/// <summary>
/// Write the required records to end the central directory.
/// </summary>
/// <param name="stream" />
/// <param name="noOfEntries">The number of entries in the directory.</param>
/// <param name="sizeEntries">The size of the entries in the directory.</param>
/// <param name="start">The start of the central directory.</param>
/// <param name="comment">The archive comment. (This can be null).</param>
internal static void WriteEndOfCentralDirectory(Stream stream, long noOfEntries, long sizeEntries, long start, byte[] comment)
{
if (noOfEntries >= 0xffff ||
start >= 0xffffffff ||
sizeEntries >= 0xffffffff)
{
WriteZip64EndOfCentralDirectory(stream, noOfEntries, sizeEntries, start);
}
stream.WriteLEInt(ZipConstants.EndOfCentralDirectorySignature);
// TODO: ZipFile Multi disk handling not done
stream.WriteLEShort(0); // number of this disk
stream.WriteLEShort(0); // no of disk with start of central dir
// Number of entries
if (noOfEntries >= 0xffff)
{
stream.WriteLEUshort(0xffff); // Zip64 marker
stream.WriteLEUshort(0xffff);
}
else
{
stream.WriteLEShort((short)noOfEntries); // entries in central dir for this disk
stream.WriteLEShort((short)noOfEntries); // total entries in central directory
}
// Size of the central directory
if (sizeEntries >= 0xffffffff)
{
stream.WriteLEUint(0xffffffff); // Zip64 marker
}
else
{
stream.WriteLEInt((int)sizeEntries);
}
// offset of start of central directory
if (start >= 0xffffffff)
{
stream.WriteLEUint(0xffffffff); // Zip64 marker
}
else
{
stream.WriteLEInt((int)start);
}
var commentLength = comment?.Length ?? 0;
if (commentLength > 0xffff)
{
throw new ZipException($"Comment length ({commentLength}) is larger than 64K");
}
stream.WriteLEShort(commentLength);
if (commentLength > 0)
{
stream.Write(comment, 0, commentLength);
}
}