private void CloseExposedStreams() { if (_exposedPublicStreams != null) { for (int i = _exposedPublicStreams.Count - 1; i >= 0; i--) { ZipIOModeEnforcingStream exposedStream = (ZipIOModeEnforcingStream)_exposedPublicStreams[i]; exposedStream.Close(); } } }
internal Stream GetStream(FileMode mode, FileAccess access) { CheckDisposed(); // the main stream held by block Manager must be compatible with the request CheckFileAccessParameter(_blockManager.Stream, access); // validate mode and Access switch (mode) { case FileMode.Create: // Check to make sure that stream isn't read only if (!_blockManager.Stream.CanWrite) { throw new InvalidOperationException(SR.Get(SRID.CanNotWriteInReadOnlyMode)); } if (_crcCalculatingStream != null && !_blockManager.Streaming) { _crcCalculatingStream.SetLength(0); } break; case FileMode.Open: break; case FileMode.OpenOrCreate: break; case FileMode.CreateNew: // because we deal with the GetStream call CreateNew is a really strange // request, as the FileInfo is already there throw new ArgumentException(SR.Get(SRID.FileModeUnsupported, "CreateNew")); case FileMode.Append: throw new ArgumentException(SR.Get(SRID.FileModeUnsupported, "Append")); case FileMode.Truncate: throw new ArgumentException(SR.Get(SRID.FileModeUnsupported, "Truncate")); default: throw new ArgumentOutOfRangeException("mode"); } // Streaming mode: always return the same stream (if it exists already) Stream exposedStream; if (_blockManager.Streaming && _exposedPublicStreams != null && _exposedPublicStreams.Count > 0) { Debug.Assert(_exposedPublicStreams.Count == 1, "Should only be one stream returned in streaming mode"); exposedStream = (Stream)_exposedPublicStreams[0]; } else { Debug.Assert((!_blockManager.Streaming) || (_exposedPublicStreams == null), "Should be first and only stream returned in streaming mode"); exposedStream = new ZipIOModeEnforcingStream(_crcCalculatingStream, access, _blockManager, this); RegisterExposedStream(exposedStream); } return(exposedStream); }
internal Stream GetStream(FileMode mode, FileAccess access) { CheckDisposed(); // the main stream held by block Manager must be compatible with the request CheckFileAccessParameter(_blockManager.Stream, access); // validate mode and Access switch(mode) { case FileMode.Create: // Check to make sure that stream isn't read only if (!_blockManager.Stream.CanWrite) { throw new InvalidOperationException(SR.Get(SRID.CanNotWriteInReadOnlyMode)); } if (_crcCalculatingStream != null && !_blockManager.Streaming) { _crcCalculatingStream.SetLength(0); } break; case FileMode.Open: break; case FileMode.OpenOrCreate: break; case FileMode.CreateNew: // because we deal with the GetStream call CreateNew is a really strange // request, as the FileInfo is already there throw new ArgumentException(SR.Get(SRID.FileModeUnsupported, "CreateNew")); case FileMode.Append: throw new ArgumentException(SR.Get(SRID.FileModeUnsupported, "Append")); case FileMode.Truncate: throw new ArgumentException(SR.Get(SRID.FileModeUnsupported, "Truncate")); default: throw new ArgumentOutOfRangeException("mode"); } // Streaming mode: always return the same stream (if it exists already) Stream exposedStream; if (_blockManager.Streaming && _exposedPublicStreams != null && _exposedPublicStreams.Count > 0) { Debug.Assert(_exposedPublicStreams.Count == 1, "Should only be one stream returned in streaming mode"); exposedStream = (Stream)_exposedPublicStreams[0]; } else { Debug.Assert((!_blockManager.Streaming) || (_exposedPublicStreams == null), "Should be first and only stream returned in streaming mode"); exposedStream = new ZipIOModeEnforcingStream(_crcCalculatingStream, access, _blockManager, this); RegisterExposedStream(exposedStream); } return exposedStream; }