private void WriteLocalFileHeaderAndDataIfNeeded() { if ((_storedUncompressedData != null) || (_compressedBytes != null)) { if (_storedUncompressedData != null) { _uncompressedSize = _storedUncompressedData.Length; using (Stream stream = new DirectToArchiveWriterStream(GetDataCompressor(_archive.ArchiveStream, true, null), this)) { _storedUncompressedData.Seek(0L, SeekOrigin.Begin); _storedUncompressedData.CopyTo(stream); _storedUncompressedData.Close(); _storedUncompressedData = null; return; } } if (_uncompressedSize == 0) { CompressionMethod = CompressionMethodValues.Stored; } WriteLocalFileHeader(false); using (MemoryStream stream2 = new MemoryStream(_compressedBytes)) { stream2.CopyTo(_archive.ArchiveStream); return; } } if ((_archive.Mode == ZipArchiveMode.Update) || !_everOpenedForWrite) { _everOpenedForWrite = true; WriteLocalFileHeader(true); } }
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(isEmptyFile: 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(isEmptyFile: true); } } }
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); } } }