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

Dispose() protected method

Dispose the stream

This method writes the Zip Central directory, then closes the stream. The application must call Dispose() (or Close) in order to produce a valid zip file.

Typically the application will call Dispose() implicitly, via a using statement in C#, or a Using statement in VB.

protected Dispose ( bool disposing ) : void
disposing bool set this to true, always.
return void
        protected override void Dispose(bool disposing)
        {
            if (_disposed) return;

            if (disposing) // not called from finalizer
            {
                // handle pending exceptions
                if (!_exceptionPending)
                {
                    _FinishCurrentEntry();
                    _directoryNeededZip64 = ZipOutput.WriteCentralDirectoryStructure(_outputStream,
                                                                                     _entriesWritten.Values,
                                                                                     1, // _numberOfSegmentsForMostRecentSave,
                                                                                     _zip64,
                                                                                     Comment,
                                                                                     new ZipContainer(this));
                    Stream wrappedStream = null;
                    CountingStream cs = _outputStream as CountingStream;
                    if (cs != null)
                    {
                        wrappedStream = cs.WrappedStream;
#if NETCF
                    cs.Close();
#else
                        cs.Dispose();
#endif
                    }
                    else
                    {
                        wrappedStream = _outputStream;
                    }

                    if (!_leaveUnderlyingStreamOpen)
                    {
#if NETCF
                    wrappedStream.Close();
#else
                        wrappedStream.Dispose();
#endif
                    }
                    _outputStream = null;
                }
            }
            _disposed = true;
        }

Usage Example

Example #1
0
            /// Raises exception on failure.
            /// On failure, existing file is untouched.
            public void Commit()
            {
                if (m_finished)
                {
                    return;
                }
                m_finished = true;

                if (m_zipstream != null)
                {
                    m_zipstream.Dispose();
                    m_zipstream = null;
                }

                string previous = m_destination + "_previous";

                Destroy(previous);
                // Don't destroy previous version until we know the new version is in place.
                try { Rename(m_destination, previous); }
                // The *NotFound exceptions are benign; they happen when writing a new file.
                // Let the other IOExceptions bubble up; they probably indicate some problem
                catch (FileNotFoundException) {}
                catch (DirectoryNotFoundException) {}
                Rename(m_temporaryPath, m_destination);
                Destroy(previous);
            }
All Usage Examples Of Ionic.Zip.ZipOutputStream::Dispose