System.IO.Compression.ZipArchiveEntry.WriteLocalFileHeaderAndDataIfNeeded C# (CSharp) Méthode

WriteLocalFileHeaderAndDataIfNeeded() private méthode

private WriteLocalFileHeaderAndDataIfNeeded ( ) : void
Résultat void
        private void WriteLocalFileHeaderAndDataIfNeeded()
        {
            //_storedUncompressedData gets frozen here, and is what gets written to the file
            if (_storedUncompressedData != null || _compressedBytes != null)
            {
                if (_storedUncompressedData != null)
                {
                    _uncompressedSize = _storedUncompressedData.Length;

                    //The compressor fills in CRC and sizes
                    //The DirectToArchiveWriterStream writes headers and such
                    using (Stream entryWriter = new DirectToArchiveWriterStream(
                                                    GetDataCompressor(_archive.ArchiveStream, true, null),
                                                    this))
                    {
                        _storedUncompressedData.Seek(0, SeekOrigin.Begin);
                        _storedUncompressedData.CopyTo(entryWriter);
                        _storedUncompressedData.Dispose();
                        _storedUncompressedData = null;
                    }
                }
                else
                {
                    // we know the sizes at this point, so just go ahead and write the headers
                    if (_uncompressedSize == 0)
                        CompressionMethod = CompressionMethodValues.Stored;
                    WriteLocalFileHeader(false);
                    foreach (byte[] compressedBytes in _compressedBytes)
                    {
                        _archive.ArchiveStream.Write(compressedBytes, 0, compressedBytes.Length);
                    }
                }
            }
            else //there is no data in the file, but if we are in update mode, we still need to write a header
            {
                if (_archive.Mode == ZipArchiveMode.Update || !_everOpenedForWrite)
                {
                    _everOpenedForWrite = true;
                    WriteLocalFileHeader(true);
                }
            }
        }