in src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs [2884:2952]
private void UpdateCommentOnly()
{
long baseLength = baseStream_.Length;
Stream updateFile;
if (archiveStorage_.UpdateMode == FileUpdateMode.Safe)
{
updateFile = archiveStorage_.MakeTemporaryCopy(baseStream_);
baseStream_.Dispose();
baseStream_ = null;
}
else
{
if (archiveStorage_.UpdateMode == FileUpdateMode.Direct)
{
// TODO: archiveStorage wasnt originally intended for this use.
// Need to revisit this to tidy up handling as archive storage currently doesnt
// handle the original stream well.
// The problem is when using an existing zip archive with an in memory archive storage.
// The open stream wont support writing but the memory storage should open the same file not an in memory one.
// Need to tidy up the archive storage interface and contract basically.
baseStream_ = archiveStorage_.OpenForDirectUpdate(baseStream_);
updateFile = baseStream_;
}
else
{
baseStream_.Dispose();
baseStream_ = null;
updateFile = new FileStream(Name, FileMode.Open, FileAccess.ReadWrite);
}
}
try
{
long locatedCentralDirOffset =
ZipFormat.LocateBlockWithSignature(updateFile, ZipConstants.EndOfCentralDirectorySignature,
baseLength, ZipConstants.EndOfCentralRecordBaseSize, 0xffff);
if (locatedCentralDirOffset < 0)
{
throw new ZipException("Cannot find central directory");
}
const int CentralHeaderCommentSizeOffset = 16;
updateFile.Position += CentralHeaderCommentSizeOffset;
byte[] rawComment = newComment_.RawComment;
updateFile.WriteLEShort(rawComment.Length);
updateFile.Write(rawComment, 0, rawComment.Length);
updateFile.SetLength(updateFile.Position);
}
finally
{
if(updateFile != baseStream_)
updateFile.Dispose();
}
if (archiveStorage_.UpdateMode == FileUpdateMode.Safe)
{
Reopen(archiveStorage_.ConvertTemporaryToFinal());
}
else
{
ReadEntries();
}
}