System.IO.Compression.ZipEndOfCentralDirectoryBlock.WriteBlock C# (CSharp) Méthode

WriteBlock() public static méthode

public static WriteBlock ( Stream stream, long numberOfEntries, long startOfCentralDirectory, long sizeOfCentralDirectory, byte archiveComment ) : void
stream Stream
numberOfEntries long
startOfCentralDirectory long
sizeOfCentralDirectory long
archiveComment byte
Résultat void
        public static void WriteBlock(Stream stream, long numberOfEntries, long startOfCentralDirectory, long sizeOfCentralDirectory, byte[] archiveComment)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            ushort numberOfEntriesTruncated = numberOfEntries > ushort.MaxValue ?
                                                        ZipHelper.Mask16Bit : (ushort)numberOfEntries;
            uint startOfCentralDirectoryTruncated = startOfCentralDirectory > uint.MaxValue ?
                                                        ZipHelper.Mask32Bit : (uint)startOfCentralDirectory;
            uint sizeOfCentralDirectoryTruncated = sizeOfCentralDirectory > uint.MaxValue ?
                                                        ZipHelper.Mask32Bit : (uint)sizeOfCentralDirectory;

            writer.Write(SignatureConstant);
            writer.Write((ushort)0);            //number of this disk
            writer.Write((ushort)0);            //number of disk with start of CD
            writer.Write(numberOfEntriesTruncated); //number of entries on this disk's cd
            writer.Write(numberOfEntriesTruncated); //number of entries in entire CD
            writer.Write(sizeOfCentralDirectoryTruncated);
            writer.Write(startOfCentralDirectoryTruncated);

            //Should be valid because of how we read archiveComment in TryReadBlock:
            Debug.Assert((archiveComment == null) || (archiveComment.Length < ushort.MaxValue));

            writer.Write(archiveComment != null ? (ushort)archiveComment.Length : (ushort)0);    //zip file comment length
            if (archiveComment != null)
                writer.Write(archiveComment);
        }

Usage Example

Exemple #1
0
        //writes eocd, and if needed, zip 64 eocd, zip64 eocd locator
        //should only throw an exception in extremely exceptional cases because it is called from dispose
        private void WriteArchiveEpilogue(long startOfCentralDirectory, long sizeOfCentralDirectory)
        {
            //determine if we need Zip 64
            bool needZip64 = false;

            if (startOfCentralDirectory >= uint.MaxValue ||
                sizeOfCentralDirectory >= uint.MaxValue ||
                _entries.Count >= ZipHelper.Mask16Bit
#if DEBUG_FORCE_ZIP64
                || _forceZip64
#endif
                )
            {
                needZip64 = true;
            }

            //if we need zip 64, write zip 64 eocd and locator
            if (needZip64)
            {
                long zip64EOCDRecordStart = _archiveStream.Position;

                Zip64EndOfCentralDirectoryRecord.WriteBlock(_archiveStream, _entries.Count, startOfCentralDirectory, sizeOfCentralDirectory);
                Zip64EndOfCentralDirectoryLocator.WriteBlock(_archiveStream, zip64EOCDRecordStart);
            }

            //write normal eocd
            ZipEndOfCentralDirectoryBlock.WriteBlock(_archiveStream, _entries.Count, startOfCentralDirectory, sizeOfCentralDirectory, _archiveComment);
        }
All Usage Examples Of System.IO.Compression.ZipEndOfCentralDirectoryBlock::WriteBlock
ZipEndOfCentralDirectoryBlock