ICSharpCode.SharpZipLib.Zip.ZipFile.UpdateCommentOnly C# (CSharp) Method

UpdateCommentOnly() private method

private UpdateCommentOnly ( ) : void
return void
        private void UpdateCommentOnly() {
            long baseLength=baseStream_.Length;

            ZipHelperStream updateFile=null;

            if (archiveStorage_.UpdateMode==FileUpdateMode.Safe) {
                Stream copyStream=archiveStorage_.MakeTemporaryCopy(baseStream_);
                updateFile=new ZipHelperStream(copyStream);
                updateFile.IsStreamOwner=true;

                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=new ZipHelperStream(baseStream_);
                } else {
                    baseStream_.Dispose();
                    baseStream_=null;
                    updateFile=new ZipHelperStream(Name);
                }
            }

            using (updateFile) {
                long locatedCentralDirOffset=
                    updateFile.LocateBlockWithSignature(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);
            }

            if (archiveStorage_.UpdateMode==FileUpdateMode.Safe) {
                Reopen(archiveStorage_.ConvertTemporaryToFinal());
            } else {
                ReadEntries();
            }
        }