/// <summary> /// ChangeMode /// </summary> /// <param name="newMode"></param> /// <remarks>Does not update Position of _current for change to ReadPassThroughMode.</remarks> private void ChangeMode(Mode newMode) { // ignore redundant calls (allowing these actually simplifies the logic in SetLength) if (newMode == _mode) { return; } // every state change requires this logic if (_current != null) { _current.Close(); _dirtyForClosing = false; _dirtyForFlushing = false; } // set the new mode - must be done before the call to Seek _mode = newMode; switch (newMode) { case Mode.Start: { _current = null; _baseStream.Position = 0; break; } case Mode.ReadPassThrough: case Mode.WritePassThrough: { Debug.Assert(_baseStream.Position == 0); // create the appropriate DeflateStream _current = new DeflateStream(_baseStream, newMode == Mode.WritePassThrough ? CompressionMode.Compress : CompressionMode.Decompress, true); break; } case Mode.Emulation: { // Create emulation stream. Use a MemoryStream for local caching. // Do not change this logic for RM cases because the data is "in the clear" and must // not be persisted in a vulnerable location. SparseMemoryStream memStream = new SparseMemoryStream(_lowWaterMark, _highWaterMark); _current = new CompressEmulationStream(_baseStream, memStream, _position, new DeflateEmulationTransform()); // verify and set length UpdateUncompressedDataLength(_current.Length); break; } case Mode.Disposed: break; default: Debug.Assert(false, "Illegal state for CompressStream - logic error"); break; } }
/// <summary> /// ChangeMode /// </summary> /// <param name="newMode"></param> /// <remarks>Does not update Position of _current for change to ReadPassThroughMode.</remarks> private void ChangeMode(Mode newMode) { // ignore redundant calls (allowing these actually simplifies the logic in SetLength) if (newMode == _mode) return; // every state change requires this logic if (_current != null) { _current.Close(); _dirtyForClosing = false; _dirtyForFlushing = false; } // set the new mode - must be done before the call to Seek _mode = newMode; switch (newMode) { case Mode.Start: { _current = null; _baseStream.Position = 0; break; } case Mode.ReadPassThrough: case Mode.WritePassThrough: { Debug.Assert(_baseStream.Position == 0); // create the appropriate DeflateStream _current = new DeflateStream(_baseStream, newMode == Mode.WritePassThrough ? CompressionMode.Compress : CompressionMode.Decompress, true); break; } case Mode.Emulation: { // Create emulation stream. Use a MemoryStream for local caching. // Do not change this logic for RM cases because the data is "in the clear" and must // not be persisted in a vulnerable location. SparseMemoryStream memStream = new SparseMemoryStream(_lowWaterMark, _highWaterMark); _current = new CompressEmulationStream(_baseStream, memStream, _position, new DeflateEmulationTransform()); // verify and set length UpdateUncompressedDataLength(_current.Length); break; } case Mode.Disposed: break; default: Debug.Assert(false, "Illegal state for CompressStream - logic error"); break; } }
IDataTransform.GetTransformedStream( Stream encodedStream, IDictionary transformContext ) { Stream tempStream = new SparseMemoryStream(_lowWaterMark, _highWaterMark); tempStream = new CompressEmulationStream(encodedStream, tempStream, 0, new CompoundFileDeflateTransform()); // return a VersionedStream that works with the VersionedStreamOwner // to verify/update our FormatVersion info return new VersionedStream(tempStream, _versionedStreamOwner); }