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
- PolyBezierSegment.cs
- NoPersistScope.cs
- HtmlHistory.cs
- ToolStripContainer.cs
- PageParser.cs
- ClrProviderManifest.cs
- EntityTypeEmitter.cs
- EndCreateSecurityTokenRequest.cs
- MD5CryptoServiceProvider.cs
- UnmanagedMemoryStream.cs
- ApplicationTrust.cs
- UpdateManifestForBrowserApplication.cs
- _ConnectOverlappedAsyncResult.cs
- ListBox.cs
- GCHandleCookieTable.cs
- CannotUnloadAppDomainException.cs
- OlePropertyStructs.cs
- externdll.cs
- MouseGesture.cs
- CancellationTokenRegistration.cs
- nulltextcontainer.cs
- QuaternionAnimation.cs
- MemberProjectionIndex.cs
- ProvideValueServiceProvider.cs
- HMACMD5.cs
- DesignerActionUIStateChangeEventArgs.cs
- GridView.cs
- ForceCopyBuildProvider.cs
- KeyGestureConverter.cs
- QilXmlWriter.cs
- TextEditorCopyPaste.cs
- GiveFeedbackEventArgs.cs
- Transform3DCollection.cs
- UserMapPath.cs
- DataRowView.cs
- IdnMapping.cs
- Registry.cs
- HttpHandlersSection.cs
- AnnouncementEventArgs.cs
- SimpleWorkerRequest.cs
- WmlLiteralTextAdapter.cs
- ExistsInCollection.cs
- EntityDataSourceWizardForm.cs
- InsufficientExecutionStackException.cs
- RoutedCommand.cs
- Control.cs
- Profiler.cs
- ResXFileRef.cs
- CompiledXpathExpr.cs
- CapabilitiesState.cs
- cookie.cs
- ItemCollection.cs
- ModelUIElement3D.cs
- Setter.cs
- DetailsViewDeletedEventArgs.cs
- SelectedGridItemChangedEvent.cs
- HttpPostServerProtocol.cs
- DictationGrammar.cs
- ChtmlTextWriter.cs
- ChildDocumentBlock.cs
- BitSet.cs
- _Win32.cs
- MediaPlayerState.cs
- KeySpline.cs
- SimpleWebHandlerParser.cs
- IisTraceWebEventProvider.cs
- Queue.cs
- XmlSchemaExporter.cs
- FullTextState.cs
- ScalarOps.cs
- RemoteCryptoRsaServiceProvider.cs
- VerificationException.cs
- XamlSerializerUtil.cs
- BackoffTimeoutHelper.cs
- SqlBulkCopy.cs
- WriterOutput.cs
- Matrix.cs
- XmlSchemaSimpleTypeUnion.cs
- FormatSelectingMessageInspector.cs
- PEFileEvidenceFactory.cs
- ClientCultureInfo.cs
- IsolatedStorageFilePermission.cs
- Polygon.cs
- SqlFormatter.cs
- XmlChildEnumerator.cs
- FileReader.cs
- ArraySortHelper.cs
- TransformConverter.cs
- CompositeControl.cs
- OdbcEnvironmentHandle.cs
- DecimalConstantAttribute.cs
- AppDomainCompilerProxy.cs
- WorkflowHostingEndpoint.cs
- PersonalizationAdministration.cs
- XmlSchemaSimpleTypeList.cs
- PartialCachingControl.cs
- GridView.cs
- GPRECT.cs
- DesignerAttribute.cs
- StatusBarItemAutomationPeer.cs