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

CommitUpdate() public method

Commit current updates, updating this archive.
ZipFile has been closed.
public CommitUpdate ( ) : void
return void
        public void CommitUpdate() {
            if (isDisposed_) {
                throw new ObjectDisposedException("ZipFile");
            }

            CheckUpdating();

            try {
                updateIndex_.Clear();
                updateIndex_=null;

                if (contentsEdited_) {
                    RunUpdates();
                } else if (commentEdited_) {
                    UpdateCommentOnly();
                } else {
                    // Create an empty archive if none existed originally.
                    if (entries_.Length==0) {
                        byte[] theComment=(newComment_!=null)
                                                ?newComment_.RawComment
                                                :ZipConstants.ConvertToArray(comment_);
                        using (var zhs=new ZipHelperStream(baseStream_)) {
                            zhs.WriteEndOfCentralDirectory(0, 0, 0, theComment);
                        }
                    }
                }
            } finally {
                PostUpdateCleanup();
            }
        }

Usage Example

Example #1
2
        void TryDeleting(byte[] master, int totalEntries, int additions, params int[] toDelete)
        {
            MemoryStream ms = new MemoryStream();
            ms.Write(master, 0, master.Length);

            using (ZipFile f = new ZipFile(ms)) {
                f.IsStreamOwner = false;
                Assert.AreEqual(totalEntries, f.Count);
                Assert.IsTrue(f.TestArchive(true));
                f.BeginUpdate(new MemoryArchiveStorage());

                for (int i = 0; i < additions; ++i) {
                    f.Add(new StringMemoryDataSource("Another great file"),
                        string.Format("Add{0}.dat", i + 1));
                }

                foreach (int i in toDelete) {
                    f.Delete(f[i]);
                }
                f.CommitUpdate();

                /* write stream to file to assist debugging.
                                byte[] data = ms.ToArray();
                                using ( FileStream fs = File.Open(@"c:\aha.zip", FileMode.Create, FileAccess.ReadWrite, FileShare.Read) ) {
                                    fs.Write(data, 0, data.Length);
                                }
                */
                int newTotal = totalEntries + additions - toDelete.Length;
                Assert.AreEqual(newTotal, f.Count,
                    string.Format("Expected {0} entries after update found {1}", newTotal, f.Count));
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }
        }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.ZipFile::CommitUpdate