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

BeginUpdate() public method

Begin updating this ZipFile archive.
ZipFile has been closed. One of the arguments provided is null ZipFile has been closed.
public BeginUpdate ( IArchiveStorage archiveStorage, IDynamicDataSource dataSource ) : void
archiveStorage IArchiveStorage The archive storage for use during the update.
dataSource IDynamicDataSource The data source to utilise during updating.
return void
        public void BeginUpdate(IArchiveStorage archiveStorage, IDynamicDataSource dataSource) {
            if (archiveStorage==null) {
                throw new ArgumentNullException("archiveStorage");
            }

            if (dataSource==null) {
                throw new ArgumentNullException("dataSource");
            }

            if (isDisposed_) {
                throw new ObjectDisposedException("ZipFile");
            }

            if (IsEmbeddedArchive) {
                throw new ZipException("Cannot update embedded/SFX archives");
            }

            archiveStorage_=archiveStorage;
            updateDataSource_=dataSource;

            // NOTE: the baseStream_ may not currently support writing or seeking.

            updateIndex_=new Dictionary<string,int>();

            updates_=new List<ZipUpdate>(entries_.Length);
            foreach (ZipEntry entry in entries_){
                int index = updates_.Count;
                updates_.Add(new ZipUpdate(entry));
                updateIndex_.Add(entry.Name, index);
            }

            // We must sort by offset before using offset's calculated sizes
            updates_.Sort(UpdateComparer);

            int idx=0;
            foreach (ZipUpdate update in updates_) {
                //If last entry, there is no next entry offset to use
                if (idx==updates_.Count-1)
                    break;

                update.OffsetBasedSize=((ZipUpdate)updates_[idx+1]).Entry.Offset-update.Entry.Offset;
                idx++;
            }
            updateCount_=updates_.Count;

            contentsEdited_=false;
            commentEdited_=false;
            newComment_=null;
        }

Same methods

ZipFile::BeginUpdate ( ) : void
ZipFile::BeginUpdate ( IArchiveStorage archiveStorage ) : void

Usage Example

Ejemplo n.º 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::BeginUpdate