public void Save() { if (this.GetDirtyFlag(true)) { long moveBlockSourceOffset = this._persistedOffset; long moveBlockSize = this._size; long moveBlockTargetOffset = this._offset; if (this._cachePrefixStream != null) { moveBlockSourceOffset += this._cachePrefixStream.Length; moveBlockTargetOffset += this._cachePrefixStream.Length; moveBlockSize -= this._cachePrefixStream.Length; } this._blockManager.MoveData(moveBlockSourceOffset, moveBlockTargetOffset, moveBlockSize); if (this._cachePrefixStream != null) { if (this._blockManager.Stream.Position != this._offset) { this._blockManager.Stream.Seek(this._offset, SeekOrigin.Begin); } this._cachePrefixStream.WriteToStream(this._blockManager.Stream); this._cachePrefixStream.Close(); this._cachePrefixStream = null; } this._persistedOffset = this._offset; this._dirtyFlag = false; } }
public override void Write(byte[] buffer, int offset, int count) { this.CheckDisposed(); PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count); if (count != 0) { int num2 = 0; this._dirtyFlag = true; this._dataChanged = true; long num = this._currentStreamPosition; if (num < this._persistedSize) { this._blockManager.Stream.Seek(this._persistedOffset + num, SeekOrigin.Begin); num2 = (int)Math.Min((long)count, this._persistedSize - num); this._blockManager.Stream.Write(buffer, offset, num2); num += num2; count -= num2; offset += num2; } if ((num + count) > this._persistedSize) { if (this._sparseMemoryStreamSuffix == null) { this._sparseMemoryStreamSuffix = new SparseMemoryStream(0x19000L, 0xa00000L); } this._sparseMemoryStreamSuffix.Seek(num - this._persistedSize, SeekOrigin.Begin); this._sparseMemoryStreamSuffix.Write(buffer, offset, count); num += count; } this._currentStreamPosition = num; this._currentStreamLength = Math.Max(this._currentStreamLength, this._currentStreamPosition); } }
public override void SetLength(long newLength) { this.CheckDisposed(); if (newLength < 0L) { throw new ArgumentOutOfRangeException("newLength"); } if (this._currentStreamLength != newLength) { this._dirtyFlag = true; this._dataChanged = true; if (newLength <= this._persistedSize) { if (this._sparseMemoryStreamSuffix != null) { this._sparseMemoryStreamSuffix.Close(); this._sparseMemoryStreamSuffix = null; } } else { if (this._sparseMemoryStreamSuffix == null) { this._sparseMemoryStreamSuffix = new SparseMemoryStream(0x19000L, 0xa00000L); } this._sparseMemoryStreamSuffix.SetLength(newLength - this._persistedSize); } this._currentStreamLength = newLength; if (this._currentStreamLength < this._currentStreamPosition) { this.Seek(this._currentStreamLength, SeekOrigin.Begin); } } }
internal void SaveStreaming() { this.CheckDisposed(); if (this._dirtyFlag) { if (this._sparseMemoryStreamSuffix != null) { this._sparseMemoryStreamSuffix.WriteToStream(this._blockManager.Stream); this._persistedSize += this._sparseMemoryStreamSuffix.Length; this._sparseMemoryStreamSuffix.Close(); this._sparseMemoryStreamSuffix = null; } this._dirtyFlag = false; this._dataChanged = false; } }
internal static PreSaveNotificationScanControlInstruction CommonPreSaveNotificationHandler(Stream stream, long offset, long size, long onDiskOffset, long onDiskSize, ref SparseMemoryStream cachePrefixStream) { if (size != 0L) { long num2; long num4; if (cachePrefixStream != null) { onDiskOffset += cachePrefixStream.Length; onDiskSize -= cachePrefixStream.Length; } if (onDiskSize == 0L) { return(PreSaveNotificationScanControlInstruction.Continue); } PackagingUtilities.CalculateOverlap(onDiskOffset, onDiskSize, offset, size, out num4, out num2); if (num2 <= 0L) { if (onDiskOffset <= offset) { return(PreSaveNotificationScanControlInstruction.Continue); } return(PreSaveNotificationScanControlInstruction.Stop); } long bytesToCopy = (num4 + num2) - onDiskOffset; if (cachePrefixStream == null) { cachePrefixStream = new SparseMemoryStream(0x19000L, 0xa00000L); } else { cachePrefixStream.Seek(0L, SeekOrigin.End); } stream.Seek(onDiskOffset, SeekOrigin.Begin); if (PackagingUtilities.CopyStream(stream, cachePrefixStream, bytesToCopy, 0x1000) != bytesToCopy) { throw new FileFormatException(SR.Get("CorruptedData")); } if ((onDiskOffset + onDiskSize) < (offset + size)) { return(PreSaveNotificationScanControlInstruction.Continue); } } return(PreSaveNotificationScanControlInstruction.Stop); }
internal void Save() { this.CheckDisposed(); if (this._dirtyFlag) { long moveBlockSourceOffset = this._persistedOffset; long moveBlockSize = Math.Min(this._persistedSize, this._currentStreamLength); long moveBlockTargetOffset = this._offset; long num = 0L; if (this._cachePrefixStream != null) { moveBlockSourceOffset += this._cachePrefixStream.Length; moveBlockTargetOffset += this._cachePrefixStream.Length; moveBlockSize -= this._cachePrefixStream.Length; } this._blockManager.MoveData(moveBlockSourceOffset, moveBlockTargetOffset, moveBlockSize); num += moveBlockSize; if (this._cachePrefixStream != null) { this._blockManager.Stream.Seek(this._offset, SeekOrigin.Begin); this._cachePrefixStream.WriteToStream(this._blockManager.Stream); num += this._cachePrefixStream.Length; this._cachePrefixStream.Close(); this._cachePrefixStream = null; } if (this._sparseMemoryStreamSuffix != null) { if (this._blockManager.Stream.Position != (this._offset + this._persistedSize)) { this._blockManager.Stream.Seek(this._offset + this._persistedSize, SeekOrigin.Begin); } this._sparseMemoryStreamSuffix.WriteToStream(this._blockManager.Stream); num += this._sparseMemoryStreamSuffix.Length; this._sparseMemoryStreamSuffix.Close(); this._sparseMemoryStreamSuffix = null; } this._blockManager.Stream.Flush(); this._persistedOffset = this._offset; this._persistedSize = num; this._dirtyFlag = false; this._dataChanged = false; } }
protected override void Dispose(bool disposing) { try { if (disposing && !this._disposedFlag) { if (this._sparseMemoryStreamSuffix != null) { this._sparseMemoryStreamSuffix.Close(); } if (this._cachePrefixStream != null) { this._cachePrefixStream.Close(); } } } finally { this._sparseMemoryStreamSuffix = null; this._cachePrefixStream = null; this._disposedFlag = true; base.Dispose(disposing); } }
private void ChangeMode(Mode newMode) { if (newMode != this._mode) { if (this._current != null) { this._current.Close(); this._dirtyForClosing = false; this._dirtyForFlushing = false; } this._mode = newMode; switch (newMode) { case Mode.Start: this._current = null; this._baseStream.Position = 0L; return; case Mode.ReadPassThrough: case Mode.WritePassThrough: this._current = new DeflateStream(this._baseStream, (newMode == Mode.WritePassThrough) ? CompressionMode.Compress : CompressionMode.Decompress, true); return; case Mode.Emulation: { SparseMemoryStream tempStream = new SparseMemoryStream(0x19000L, 0xa00000L); this._current = new CompressEmulationStream(this._baseStream, tempStream, this._position, new DeflateEmulationTransform()); this.UpdateUncompressedDataLength(this._current.Length); return; } case Mode.Disposed: return; } } }