ICSharpCode.SharpZipLib.Zip.ZipOutputStream.CloseEntry C# (CSharp) Méthode

CloseEntry() public méthode

Closes the current entry, updating header and footer information as required
/// An I/O error occurs. /// /// No entry is active. ///
public CloseEntry ( ) : void
Résultat void
        public void CloseEntry()
        {
            if (curEntry == null) {
                throw new InvalidOperationException("No open entry");
            }

            long csize = size;

            // First finish the deflater, if appropriate
            if (curMethod == CompressionMethod.Deflated) {
                if (size >= 0) {
                    base.Finish();
                    csize = deflater_.TotalOut;
                } else {
                    deflater_.Reset();
                }
            }

            // Write the AES Authentication Code (a hash of the compressed and encrypted data)
            if (curEntry.AESKeySize > 0) {
                baseOutputStream_.Write(AESAuthCode, 0, 10);
            }

            if (curEntry.Size < 0) {
                curEntry.Size = size;
            } else if (curEntry.Size != size) {
                throw new ZipException("size was " + size + ", but I expected " + curEntry.Size);
            }

            if (curEntry.CompressedSize < 0) {
                curEntry.CompressedSize = csize;
            } else if (curEntry.CompressedSize != csize) {
                throw new ZipException("compressed size was " + csize + ", but I expected " + curEntry.CompressedSize);
            }

            if (curEntry.Crc < 0) {
                curEntry.Crc = crc.Value;
            } else if (curEntry.Crc != crc.Value) {
                throw new ZipException("crc was " + crc.Value + ", but I expected " + curEntry.Crc);
            }

            offset += csize;

            if (curEntry.IsCrypted) {
                if (curEntry.AESKeySize > 0) {
                    curEntry.CompressedSize += curEntry.AESOverheadSize;

                } else {
                    curEntry.CompressedSize += ZipConstants.CryptoHeaderSize;
                }
            }

            // Patch the header if possible
            if (patchEntryHeader) {
                patchEntryHeader = false;

                long curPos = baseOutputStream_.Position;
                baseOutputStream_.Seek(crcPatchPos, SeekOrigin.Begin);
                WriteLeInt((int)curEntry.Crc);

                if (curEntry.LocalHeaderRequiresZip64) {

                    if (sizePatchPos == -1) {
                        throw new ZipException("Entry requires zip64 but this has been turned off");
                    }

                    baseOutputStream_.Seek(sizePatchPos, SeekOrigin.Begin);
                    WriteLeLong(curEntry.Size);
                    WriteLeLong(curEntry.CompressedSize);
                } else {
                    WriteLeInt((int)curEntry.CompressedSize);
                    WriteLeInt((int)curEntry.Size);
                }
                baseOutputStream_.Seek(curPos, SeekOrigin.Begin);
            }

            // Add data descriptor if flagged as required
            if ((curEntry.Flags & 8) != 0) {
                WriteLeInt(ZipConstants.DataDescriptorSignature);
                WriteLeInt(unchecked((int)curEntry.Crc));

                if (curEntry.LocalHeaderRequiresZip64) {
                    WriteLeLong(curEntry.CompressedSize);
                    WriteLeLong(curEntry.Size);
                    offset += ZipConstants.Zip64DataDescriptorSize;
                } else {
                    WriteLeInt((int)curEntry.CompressedSize);
                    WriteLeInt((int)curEntry.Size);
                    offset += ZipConstants.DataDescriptorSize;
                }
            }

            entries.Add(curEntry);
            curEntry = null;
        }

Usage Example

        /// <summary>
        /// Creates a bundle containing version list delta and all data of files.
        /// </summary>
        /// <returns>The binary bundle.</returns>
        /// <param name="list">List needed to transferred.</param>
        public static byte[] CreateFileBundle(List<FileEvent> list)
        {
            using (MemoryStream ms = new MemoryStream())
            using (ZipOutputStream zip = new ZipOutputStream(ms))
            {
                ZipEntry block = new ZipEntry("vs");
                zip.PutNextEntry(block);
                zip.WriteAllBytes(list.SerializeAsBytes());
                zip.CloseEntry();

                foreach (var sha1 in list.Where(x => x.SHA1 != null).Select(x => x.SHA1).Distinct())
                {
                    block = new ZipEntry(sha1);
                    zip.PutNextEntry(block);
                    zip.WriteAllBytes(File.ReadAllBytes(Config.MetaFolderData.File(sha1)));
                    zip.CloseEntry();
                }

                zip.Finish();
                ms.Flush();
                ms.Position = 0;

                return ms.ToArray();
            }
        }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.ZipOutputStream::CloseEntry