ICSharpCode.SharpZipLib.Zip.ZipHelperStream.WriteEndOfCentralDirectory C# (CSharp) Méthode

WriteEndOfCentralDirectory() public méthode

Write the required records to end the central directory.
public WriteEndOfCentralDirectory ( long noOfEntries, long sizeEntries, long startOfCentralDirectory, byte comment ) : void
noOfEntries long The number of entries in the directory.
sizeEntries long The size of the entries in the directory.
startOfCentralDirectory long The start of the central directory.
comment byte The archive comment. (This can be null).
Résultat void
        public void WriteEndOfCentralDirectory(long noOfEntries, long sizeEntries,
			long startOfCentralDirectory, byte[] comment)
        {
            if ((noOfEntries >= 0xffff) ||
                (startOfCentralDirectory >= 0xffffffff) ||
                (sizeEntries >= 0xffffffff)) {
                WriteZip64EndOfCentralDirectory(noOfEntries, sizeEntries, startOfCentralDirectory);
            }

            WriteLEInt(ZipConstants.EndOfCentralDirectorySignature);

            // TODO: ZipFile Multi disk handling not done
            WriteLEShort(0);                    // number of this disk
            WriteLEShort(0);                    // no of disk with start of central dir

            // Number of entries
            if (noOfEntries >= 0xffff) {
                WriteLEUshort(0xffff);  // Zip64 marker
                WriteLEUshort(0xffff);
            } else {
                WriteLEShort((short)noOfEntries);          // entries in central dir for this disk
                WriteLEShort((short)noOfEntries);          // total entries in central directory
            }

            // Size of the central directory
            if (sizeEntries >= 0xffffffff) {
                WriteLEUint(0xffffffff);    // Zip64 marker
            } else {
                WriteLEInt((int)sizeEntries);
            }

            // offset of start of central directory
            if (startOfCentralDirectory >= 0xffffffff) {
                WriteLEUint(0xffffffff);    // Zip64 marker
            } else {
                WriteLEInt((int)startOfCentralDirectory);
            }

            int commentLength = (comment != null) ? comment.Length : 0;

            if (commentLength > 0xffff) {
                throw new ZipException(string.Format("Comment length({0}) is too long can only be 64K", commentLength));
            }

            WriteLEShort(commentLength);

            if (commentLength > 0) {
                Write(comment, 0, comment.Length);
            }
        }

Usage Example

Exemple #1
0
		/// <summary>
		/// Commit current updates, updating this archive.
		/// </summary>
		/// <seealso cref="BeginUpdate()"></seealso>
		/// <seealso cref="AbortUpdate"></seealso>
		/// <exception cref="ObjectDisposedException">ZipFile has been closed.</exception>
		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( ZipHelperStream zhs=new ZipHelperStream(baseStream_) ) {
							zhs.WriteEndOfCentralDirectory(0, 0, 0, theComment);
						}
					}
				}

			}
			finally {
				PostUpdateCleanup();
			}
		}
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.ZipHelperStream::WriteEndOfCentralDirectory