public void CloseEntry()
{
if (curEntry == null) {
throw new InvalidOperationException("No open entry");
}
long csize = size;
// First finish the deflater, if appropriate
if (curMethod == CompressionMethod.Deflated) {
if (size >= 0) {
base.Finish();
csize = deflater_.TotalOut;
} else {
deflater_.Reset();
}
}
// Write the AES Authentication Code (a hash of the compressed and encrypted data)
if (curEntry.AESKeySize > 0) {
baseOutputStream_.Write(AESAuthCode, 0, 10);
}
if (curEntry.Size < 0) {
curEntry.Size = size;
} else if (curEntry.Size != size) {
throw new ZipException("size was " + size + ", but I expected " + curEntry.Size);
}
if (curEntry.CompressedSize < 0) {
curEntry.CompressedSize = csize;
} else if (curEntry.CompressedSize != csize) {
throw new ZipException("compressed size was " + csize + ", but I expected " + curEntry.CompressedSize);
}
if (curEntry.Crc < 0) {
curEntry.Crc = crc.Value;
} else if (curEntry.Crc != crc.Value) {
throw new ZipException("crc was " + crc.Value + ", but I expected " + curEntry.Crc);
}
offset += csize;
if (curEntry.IsCrypted) {
if (curEntry.AESKeySize > 0) {
curEntry.CompressedSize += curEntry.AESOverheadSize;
} else {
curEntry.CompressedSize += ZipConstants.CryptoHeaderSize;
}
}
// Patch the header if possible
if (patchEntryHeader) {
patchEntryHeader = false;
long curPos = baseOutputStream_.Position;
baseOutputStream_.Seek(crcPatchPos, SeekOrigin.Begin);
WriteLeInt((int)curEntry.Crc);
if (curEntry.LocalHeaderRequiresZip64) {
if (sizePatchPos == -1) {
throw new ZipException("Entry requires zip64 but this has been turned off");
}
baseOutputStream_.Seek(sizePatchPos, SeekOrigin.Begin);
WriteLeLong(curEntry.Size);
WriteLeLong(curEntry.CompressedSize);
} else {
WriteLeInt((int)curEntry.CompressedSize);
WriteLeInt((int)curEntry.Size);
}
baseOutputStream_.Seek(curPos, SeekOrigin.Begin);
}
// Add data descriptor if flagged as required
if ((curEntry.Flags & 8) != 0) {
WriteLeInt(ZipConstants.DataDescriptorSignature);
WriteLeInt(unchecked((int)curEntry.Crc));
if (curEntry.LocalHeaderRequiresZip64) {
WriteLeLong(curEntry.CompressedSize);
WriteLeLong(curEntry.Size);
offset += ZipConstants.Zip64DataDescriptorSize;
} else {
WriteLeInt((int)curEntry.CompressedSize);
WriteLeInt((int)curEntry.Size);
offset += ZipConstants.DataDescriptorSize;
}
}
entries.Add(curEntry);
curEntry = null;
}