private CheckSumAndSizeWriteStream GetDataCompressor(Stream backingStream, bool leaveBackingStreamOpen, EventHandler onClose) { // stream stack: backingStream -> DeflateStream -> CheckSumWriteStream // we should always be compressing with deflate. Stored is used for empty files, but we don't actually // call through this function for that - we just write the stored value in the header Debug.Assert(CompressionMethod == CompressionMethodValues.Deflate); Stream compressorStream = _compressionLevel.HasValue ? new DeflateStream(backingStream, _compressionLevel.Value, leaveBackingStreamOpen) : new DeflateStream(backingStream, CompressionMode.Compress, leaveBackingStreamOpen); bool isIntermediateStream = true; bool leaveCompressorStreamOpenOnClose = leaveBackingStreamOpen && !isIntermediateStream; var checkSumStream = new CheckSumAndSizeWriteStream( compressorStream, backingStream, leaveCompressorStreamOpenOnClose, this, onClose, (long initialPosition, long currentPosition, uint checkSum, Stream backing, ZipArchiveEntry thisRef, EventHandler closeHandler) => { thisRef._crc32 = checkSum; thisRef._uncompressedSize = currentPosition; thisRef._compressedSize = backing.Position - initialPosition; closeHandler?.Invoke(thisRef, EventArgs.Empty); }); return(checkSumStream); }
public DirectToArchiveWriterStream(CheckSumAndSizeWriteStream crcSizeStream, ZipArchiveEntry entry) { this._position = (long)0; this._crcSizeStream = crcSizeStream; this._everWritten = false; this._isDisposed = false; this._entry = entry; this._usedZip64inLH = false; this._canWrite = true; }
// makes the assumption that somewhere down the line, crcSizeStream is eventually writing directly to the archive // this class calls other functions on ZipArchiveEntry that write directly to the archive public DirectToArchiveWriterStream(CheckSumAndSizeWriteStream crcSizeStream, ZipArchiveEntry entry) { _position = 0; _crcSizeStream = crcSizeStream; _everWritten = false; _isDisposed = false; _entry = entry; _usedZip64inLH = false; _canWrite = true; }
private Stream OpenInWriteMode() { if (this._everOpenedForWrite) { throw new IOException(Messages.CreateModeWriteOnceAndOneEntryAtATime); } this._everOpenedForWrite = true; CheckSumAndSizeWriteStream dataCompressor = this.GetDataCompressor(this._archive.ArchiveStream, true, (object o, EventArgs e) => { this._archive.ReleaseArchiveStream(this); this._outstandingWriteStream = null; }); this._outstandingWriteStream = new ZipArchiveEntry.DirectToArchiveWriterStream(dataCompressor, this); return(new WrappedStream(this._outstandingWriteStream, (object o, EventArgs e) => this._outstandingWriteStream.Close())); }
private CheckSumAndSizeWriteStream GetDataCompressor(Stream backingStream, bool leaveBackingStreamOpen, EventHandler onClose) { Stream stream = (this._compressionLevel.HasValue ? new DeflateStream(backingStream, this._compressionLevel.Value, leaveBackingStreamOpen) : new DeflateStream(backingStream, CompressionMode.Compress, leaveBackingStreamOpen)); bool flag = (!leaveBackingStreamOpen ? false : false); CheckSumAndSizeWriteStream checkSumAndSizeWriteStream = new CheckSumAndSizeWriteStream(stream, backingStream, flag, (long initialPosition, long currentPosition, uint checkSum) => { this._crc32 = checkSum; this._uncompressedSize = currentPosition; this._compressedSize = backingStream.Position - initialPosition; if (onClose != null) { onClose(this, EventArgs.Empty); } }); return(checkSumAndSizeWriteStream); }
private Stream OpenInWriteMode() { if (_everOpenedForWrite) { throw new IOException(); } // we assume that if another entry grabbed the archive stream, that it set this entry's _everOpenedForWrite property to true by calling WriteLocalFileHeaderIfNeeed _archive.DebugAssertIsStillArchiveStreamOwner(this); _everOpenedForWrite = true; CheckSumAndSizeWriteStream crcSizeStream = GetDataCompressor(_archive.ArchiveStream, true, (object o, EventArgs e) => { // release the archive stream var entry = (ZipArchiveEntry)o; entry._archive.ReleaseArchiveStream(entry); entry._outstandingWriteStream = null; }); _outstandingWriteStream = new DirectToArchiveWriterStream(crcSizeStream, this); return(new WrappedStream(baseStream: _outstandingWriteStream, closeBaseStream: true)); }
private CheckSumAndSizeWriteStream GetDataCompressor(Stream backingStream, Boolean leaveBackingStreamOpen, EventHandler onClose) { //stream stack: backingStream -> DeflateStream -> CheckSumWriteStream //we should always be compressing with deflate. Stored is used for empty files, but we don't actually //call through this function for that - we just write the stored value in the header Debug.Assert(CompressionMethod == CompressionMethodValues.Deflate); Stream compressorStream = _compressionLevel.HasValue ? new DeflateStream(backingStream, _compressionLevel.Value, leaveBackingStreamOpen) : new DeflateStream(backingStream, CompressionMode.Compress, leaveBackingStreamOpen); Boolean isIntermediateStream = true; Boolean leaveCompressorStreamOpenOnClose = leaveBackingStreamOpen && !isIntermediateStream; var checkSumStream = new CheckSumAndSizeWriteStream( compressorStream, backingStream, leaveCompressorStreamOpenOnClose, this, onClose, (Int64 initialPosition, Int64 currentPosition, UInt32 checkSum, Stream backing, ZipArchiveEntry thisRef, EventHandler closeHandler) => { thisRef._crc32 = checkSum; thisRef._uncompressedSize = currentPosition; thisRef._compressedSize = backing.Position - initialPosition; if (closeHandler != null) closeHandler(thisRef, EventArgs.Empty); }); return checkSumStream; }
//makes the assumption that somewhere down the line, crcSizeStream is eventually writing directly to the archive //this class calls other functions on ZipArchiveEntry that write directly to the archive public DirectToArchiveWriterStream(CheckSumAndSizeWriteStream crcSizeStream, ZipArchiveEntry entry) { _position = 0; _crcSizeStream = crcSizeStream; _everWritten = false; _isDisposed = false; _entry = entry; _usedZip64inLH = false; _canWrite = true; }