Ionic.Zip.ZipOutputStream.PutNextEntry C# (CSharp) Method

PutNextEntry() public method

Specify the name of the next entry that will be written to the zip file.

Call this method just before calling Write(byte[], int, int), to specify the name of the entry that the next set of bytes written to the ZipOutputStream belongs to. All subsequent calls to Write, until the next call to PutNextEntry, will be inserted into the named entry in the zip file.

If the entryName used in PutNextEntry() ends in a slash, then the entry added is marked as a directory. Because directory entries do not contain data, a call to Write(), before an intervening additional call to PutNextEntry(), will throw an exception.

If you don't call Write() between two calls to PutNextEntry(), the first entry is inserted into the zip file as a file of zero size. This may be what you want.

Because PutNextEntry() closes out the prior entry, if any, this method may throw if there is a problem with the prior entry.

This method returns the ZipEntry. You can modify public properties on the ZipEntry, such as ZipEntry.Encryption, , and so on, until the first call to ZipOutputStream.Write(), or until the next call to PutNextEntry(). If you modify the ZipEntry after having called Write(), you may get a runtime exception, or you may silently get an invalid zip archive.

public PutNextEntry ( String entryName ) : ZipEntry
entryName String /// The name of the entry to be added, including any path to be used /// within the zip file. ///
return ZipEntry
        public ZipEntry PutNextEntry(String entryName)
        {
            if (String.IsNullOrEmpty(entryName))
                throw new ArgumentNullException("entryName");

            if (_disposed)
            {
                _exceptionPending = true;
                throw new System.InvalidOperationException("The stream has been closed.");
            }

            _FinishCurrentEntry();
            _currentEntry = ZipEntry.CreateForZipOutputStream(entryName);
            _currentEntry._container = new ZipContainer(this);
            _currentEntry._BitField |= 0x0008;  // workitem 8932
            _currentEntry.SetEntryTimes(DateTime.Now, DateTime.Now, DateTime.Now);
            _currentEntry.CompressionLevel = this.CompressionLevel;
            _currentEntry.CompressionMethod = this.CompressionMethod;
            _currentEntry.Password = _password; // workitem 13909
            _currentEntry.Encryption = this.Encryption;
            // workitem 12634
            _currentEntry.AlternateEncoding = this.AlternateEncoding;
            _currentEntry.AlternateEncodingUsage = this.AlternateEncodingUsage;

            if (entryName.EndsWith("/"))  _currentEntry.MarkAsDirectory();

            _currentEntry.EmitTimesInWindowsFormatWhenSaving = ((_timestamp & ZipEntryTimestamp.Windows) != 0);
            _currentEntry.EmitTimesInUnixFormatWhenSaving = ((_timestamp & ZipEntryTimestamp.Unix) != 0);
            InsureUniqueEntry(_currentEntry);
            _needToWriteEntryHeader = true;

            return _currentEntry;
        }

Usage Example

Example #1
0
            /// Returns a writable stream to an empty subfile.
            public Stream GetWriteStream(string subfileName)
            {
                Debug.Assert(!m_finished);
                if (m_zipstream != null)
                {
#if USE_DOTNETZIP
                    var entry = m_zipstream.PutNextEntry(subfileName);
                    entry.LastModified = System.DateTime.Now;
                    // entry.CompressionMethod = DotNetZip.CompressionMethod.None; no need; use the default
                    return(new ZipOutputStreamWrapper_DotNetZip(m_zipstream));
#else
                    var entry = new ZipLibrary.ZipEntry(subfileName);
                    entry.DateTime = System.DateTime.Now;
                    // There is such a thing as "Deflated, compression level 0".
                    // Explicitly use "Stored".
                    entry.CompressionMethod = (m_zipstream.GetLevel() == 0)
          ? ZipLibrary.CompressionMethod.Stored
          : ZipLibrary.CompressionMethod.Deflated;
                    return(new ZipOutputStreamWrapper_SharpZipLib(m_zipstream, entry));
#endif
                }
                else
                {
                    Directory.CreateDirectory(m_temporaryPath);
                    string fullPath = Path.Combine(m_temporaryPath, subfileName);
                    return(new FileStream(fullPath, FileMode.Create, FileAccess.Write));
                }
            }
All Usage Examples Of Ionic.Zip.ZipOutputStream::PutNextEntry