Code:
/ 4.0 / 4.0 / 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. 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
- ScriptDescriptor.cs
- ExtenderProvidedPropertyAttribute.cs
- ServerProtocol.cs
- AttributeData.cs
- TransactionManager.cs
- TdsParserHelperClasses.cs
- EventWaitHandleSecurity.cs
- precedingquery.cs
- DbConnectionStringBuilder.cs
- Clipboard.cs
- CorruptingExceptionCommon.cs
- EmptyReadOnlyDictionaryInternal.cs
- SortAction.cs
- BindingCompleteEventArgs.cs
- SoapEnumAttribute.cs
- RtfControls.cs
- WindowInteractionStateTracker.cs
- HMAC.cs
- SchemaNotation.cs
- InputScope.cs
- NamedPipeDuplicateContext.cs
- ResXDataNode.cs
- Oid.cs
- Point3D.cs
- CompilerWrapper.cs
- TextEvent.cs
- HostSecurityManager.cs
- SQLGuid.cs
- DiscreteKeyFrames.cs
- LayoutExceptionEventArgs.cs
- WmpBitmapDecoder.cs
- RegistryConfigurationProvider.cs
- Underline.cs
- WebPartConnectVerb.cs
- PublisherMembershipCondition.cs
- DocumentPageView.cs
- StringAttributeCollection.cs
- SingleConverter.cs
- SingleSelectRootGridEntry.cs
- TextDecorationCollection.cs
- MSHTMLHostUtil.cs
- HighlightVisual.cs
- SettingsPropertyValueCollection.cs
- ProcessModelInfo.cs
- StreamedFramingRequestChannel.cs
- Cursors.cs
- Nullable.cs
- XamlSerializerUtil.cs
- FormatConvertedBitmap.cs
- CompoundFileStorageReference.cs
- BackgroundFormatInfo.cs
- XmlSchemaAnyAttribute.cs
- MonthCalendar.cs
- ColumnTypeConverter.cs
- DataRecordInternal.cs
- OuterGlowBitmapEffect.cs
- SiteMapNode.cs
- ObjectParameterCollection.cs
- WSHttpSecurity.cs
- DateTimeConverter2.cs
- ArrayConverter.cs
- XmlSchemaIdentityConstraint.cs
- RelationshipDetailsRow.cs
- XmlnsCompatibleWithAttribute.cs
- TdsRecordBufferSetter.cs
- RelAssertionDirectKeyIdentifierClause.cs
- Schema.cs
- WebPartZone.cs
- SpotLight.cs
- IsolatedStoragePermission.cs
- CharacterMetricsDictionary.cs
- XmlSerializationWriter.cs
- MessageQueuePermissionEntryCollection.cs
- WebScriptMetadataMessage.cs
- MessageQuerySet.cs
- GenericsInstances.cs
- Header.cs
- XPathNodeHelper.cs
- ValueSerializer.cs
- ECDiffieHellman.cs
- WhereQueryOperator.cs
- FilterQuery.cs
- CheckPair.cs
- BindingFormattingDialog.cs
- DirectoryInfo.cs
- XmlTextWriter.cs
- ListViewHitTestInfo.cs
- sqlmetadatafactory.cs
- ConfigurationManager.cs
- OleDbMetaDataFactory.cs
- CodeTypeParameter.cs
- ResetableIterator.cs
- ToolBarOverflowPanel.cs
- AuthenticatedStream.cs
- ContextInformation.cs
- ExpressionPrinter.cs
- DataIdProcessor.cs
- TabletCollection.cs
- LookupBindingPropertiesAttribute.cs
- DefaultHttpHandler.cs