Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Sys / System / IO / compression / GZipStream.cs / 1305376 / GZipStream.cs
namespace System.IO.Compression { using System.IO; using System.Diagnostics; using System.Security.Permissions; public class GZipStream : Stream { private DeflateStream deflateStream; public GZipStream(Stream stream, CompressionMode mode) : this( stream, mode, false) { } public GZipStream(Stream stream, CompressionMode mode, bool leaveOpen) { deflateStream = new DeflateStream(stream, mode, leaveOpen); if (mode == CompressionMode.Compress) { IFileFormatWriter writeCommand = new GZipFormatter(); deflateStream.SetFileFormatWriter(writeCommand); } else { IFileFormatReader readCommand = new GZipDecoder(); deflateStream.SetFileFormatReader(readCommand); } } public override bool CanRead { get { if( deflateStream == null) { return false; } return deflateStream.CanRead; } } public override bool CanWrite { get { if( deflateStream == null) { return false; } return deflateStream.CanWrite; } } public override bool CanSeek { get { if( deflateStream == null) { return false; } return deflateStream.CanSeek; } } public override long Length { get { throw new NotSupportedException(SR.GetString(SR.NotSupported)); } } public override long Position { get { throw new NotSupportedException(SR.GetString(SR.NotSupported)); } set { throw new NotSupportedException(SR.GetString(SR.NotSupported)); } } public override void Flush() { if( deflateStream == null) { throw new ObjectDisposedException(null, SR.GetString(SR.ObjectDisposed_StreamClosed)); } deflateStream.Flush(); return; } public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(SR.GetString(SR.NotSupported)); } public override void SetLength(long value) { throw new NotSupportedException(SR.GetString(SR.NotSupported)); } [HostProtection(ExternalThreading=true)] public override IAsyncResult BeginRead(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { if( deflateStream == null) { throw new InvalidOperationException(SR.GetString(SR.ObjectDisposed_StreamClosed)); } return deflateStream.BeginRead(array, offset, count, asyncCallback, asyncState); } public override int EndRead(IAsyncResult asyncResult) { if( deflateStream == null) { throw new InvalidOperationException(SR.GetString(SR.ObjectDisposed_StreamClosed)); } return deflateStream.EndRead(asyncResult); } [HostProtection(ExternalThreading=true)] public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { if( deflateStream == null) { throw new InvalidOperationException(SR.GetString(SR.ObjectDisposed_StreamClosed)); } return deflateStream.BeginWrite(array, offset, count, asyncCallback, asyncState); } public override void EndWrite(IAsyncResult asyncResult) { if( deflateStream == null) { throw new InvalidOperationException(SR.GetString(SR.ObjectDisposed_StreamClosed)); } deflateStream.EndWrite(asyncResult); } public override int Read(byte[] array, int offset, int count) { if( deflateStream == null) { throw new ObjectDisposedException(null, SR.GetString(SR.ObjectDisposed_StreamClosed)); } return deflateStream.Read(array, offset, count); } public override void Write(byte[] array, int offset, int count) { if( deflateStream == null) { throw new ObjectDisposedException(null, SR.GetString(SR.ObjectDisposed_StreamClosed)); } deflateStream.Write(array, offset, count); } protected override void Dispose(bool disposing) { try { if (disposing && deflateStream != null) { deflateStream.Close(); } deflateStream = null; } finally { base.Dispose(disposing); } } public Stream BaseStream { get { if( deflateStream != null) { return deflateStream.BaseStream; } else { return null; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebBrowser.cs
- UITypeEditor.cs
- NavigationPropertyEmitter.cs
- BamlLocalizableResourceKey.cs
- PropertyChangedEventManager.cs
- DataViewManager.cs
- MouseWheelEventArgs.cs
- LineSegment.cs
- NullRuntimeConfig.cs
- ValidationErrorEventArgs.cs
- EditorPart.cs
- LinqDataSourceDeleteEventArgs.cs
- HealthMonitoringSectionHelper.cs
- PropertyValueEditor.cs
- _NestedMultipleAsyncResult.cs
- ActivitiesCollection.cs
- InheritedPropertyChangedEventArgs.cs
- ReadOnlyObservableCollection.cs
- WebEventTraceProvider.cs
- ObjectComplexPropertyMapping.cs
- MultilineStringConverter.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- SelectionPatternIdentifiers.cs
- UInt32.cs
- FlowLayout.cs
- ToolStripSeparatorRenderEventArgs.cs
- TypePresenter.xaml.cs
- TableHeaderCell.cs
- LocalizabilityAttribute.cs
- ProgressBarBrushConverter.cs
- RowParagraph.cs
- BitmapFrame.cs
- CommonDialog.cs
- XPathNavigatorReader.cs
- RoutedPropertyChangedEventArgs.cs
- SerializationSectionGroup.cs
- TimeBoundedCache.cs
- DataTable.cs
- DataGridViewIntLinkedList.cs
- Attributes.cs
- Schedule.cs
- CaseInsensitiveHashCodeProvider.cs
- TableRowCollection.cs
- ColorTranslator.cs
- KnownBoxes.cs
- NoResizeHandleGlyph.cs
- IdentityReference.cs
- KeyEventArgs.cs
- HandleCollector.cs
- SessionSymmetricMessageSecurityProtocolFactory.cs
- XamlFilter.cs
- PersianCalendar.cs
- SqlParameterizer.cs
- InvalidDataContractException.cs
- DateTimeOffset.cs
- CompositeKey.cs
- TypeBuilder.cs
- BaseValidator.cs
- SHA256Managed.cs
- ContentPresenter.cs
- TextDocumentView.cs
- WarningException.cs
- BamlBinaryWriter.cs
- AspNetHostingPermission.cs
- WebPartCatalogAddVerb.cs
- PublisherMembershipCondition.cs
- PerformanceCountersElement.cs
- MachinePropertyVariants.cs
- Viewport2DVisual3D.cs
- HostingEnvironmentException.cs
- WindowsServiceElement.cs
- MetadataPropertyvalue.cs
- CollectionMarkupSerializer.cs
- ServiceModelEnhancedConfigurationElementCollection.cs
- SqlTriggerAttribute.cs
- XmlAggregates.cs
- StylusPoint.cs
- TargetParameterCountException.cs
- SchemaNotation.cs
- peernodestatemanager.cs
- SchemaTableColumn.cs
- basecomparevalidator.cs
- Scene3D.cs
- StreamDocument.cs
- TypeSystem.cs
- AttributeAction.cs
- ToolBarPanel.cs
- KeyFrames.cs
- OwnerDrawPropertyBag.cs
- SqlProfileProvider.cs
- BuildManagerHost.cs
- Persist.cs
- ValidationSummary.cs
- Typography.cs
- ISO2022Encoding.cs
- QuestionEventArgs.cs
- IListConverters.cs
- HttpHeaderCollection.cs
- Utils.cs
- HttpClientChannel.cs