GZipStream Class

Provides methods and properties used to compress and decompress streams.

System.Object
  System.MarshalByRefObject
    System.IO.Stream
      System.IO.Compression.GZipStream

Namespace:  System.IO.Compression
Assembly:  System (in System.dll)

type GZipStream =  
    class 
        inherit Stream 
    end

The GZipStream type exposes the following members.

  NameDescription
Public methodSupported in .NET for Windows Store appsGZipStream(Stream, CompressionLevel)Initializes a new instance of the GZipStream class by using the specified stream and compression level.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGZipStream(Stream, CompressionMode)Initializes a new instance of the GZipStream class by using the specified stream and compression mode.
Public methodSupported in .NET for Windows Store appsGZipStream(Stream, CompressionLevel, Boolean)Initializes a new instance of the GZipStream class by using the specified stream and compression level, and optionally leaves the stream open.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGZipStream(Stream, CompressionMode, Boolean)Initializes a new instance of the GZipStream class by using the specified stream and compression mode, and optionally leaves the stream open.
Top

  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBaseStreamGets a reference to the underlying stream.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanReadGets a value indicating whether the stream supports reading while decompressing a file. (Overrides Stream.CanRead.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanSeekGets a value indicating whether the stream supports seeking. (Overrides Stream.CanSeek.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanTimeoutGets a value that determines whether the current stream can time out. (Inherited from Stream.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanWriteGets a value indicating whether the stream supports writing. (Overrides Stream.CanWrite.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLengthThis property is not supported and always throws a NotSupportedException. (Overrides Stream.Length.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsPositionThis property is not supported and always throws a NotSupportedException. (Overrides Stream.Position.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadTimeoutGets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out. (Inherited from Stream.)
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsWriteTimeoutGets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out. (Inherited from Stream.)
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryBeginReadBegins an asynchronous read operation. (Consider using the Stream.ReadAsync method instead; see the Remarks section.) (Overrides Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryBeginWriteBegins an asynchronous write operation. (Consider using the Stream.WriteAsync method instead; see the Remarks section.) (Overrides Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).)
Public methodSupported by the XNA FrameworkCloseCloses the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed. (Inherited from Stream.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCopyTo(Stream)Reads the bytes from the current stream and writes them to another stream. (Inherited from Stream.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCopyTo(Stream, Int32)Reads the bytes from the current stream and writes them to another stream, using a specified buffer size. (Inherited from Stream.)
Public methodSupported in .NET for Windows Store appsCopyToAsync(Stream)Asynchronously reads the bytes from the current stream and writes them to another stream. (Inherited from Stream.)
Public methodSupported in .NET for Windows Store appsCopyToAsync(Stream, Int32)Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size. (Inherited from Stream.)
Public methodSupported in .NET for Windows Store appsCopyToAsync(Stream, Int32, CancellationToken)Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. (Inherited from Stream.)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Protected methodSupported by the XNA FrameworkCreateWaitHandle Obsolete. Allocates a WaitHandle object. (Inherited from Stream.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsDispose()Releases all resources used by the Stream. (Inherited from Stream.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsDispose(Boolean)Releases the unmanaged resources used by the GZipStream and optionally releases the managed resources. (Overrides Stream.Dispose(Boolean).)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEndReadWaits for the pending asynchronous read to complete. (Consider using the the Stream.ReadAsync method instead; see the Remarks section.) (Overrides Stream.EndRead(IAsyncResult).)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEndWriteHandles the end of an asynchronous write operation. (Consider using the Stream.WriteAsync method instead; see the Remarks section.) (Overrides Stream.EndWrite(IAsyncResult).)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFlushThe current implementation of this method has no functionality. (Overrides Stream.Flush().)
Public methodSupported in .NET for Windows Store appsFlushAsync()Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device. (Inherited from Stream.)
Public methodSupported in .NET for Windows Store appsFlushAsync(CancellationToken)Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests. (Inherited from Stream.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodObjectInvariantInfrastructure. Obsolete. Provides support for a Contract. (Inherited from Stream.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadReads a number of decompressed bytes into the specified byte array. (Overrides Stream.Read(Byte[], Int32, Int32).)
Public methodSupported in .NET for Windows Store appsReadAsync(Byte[], Int32, Int32)Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. (Inherited from Stream.)
Public methodSupported in .NET for Windows Store appsReadAsync(Byte[], Int32, Int32, CancellationToken)Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests. (Inherited from Stream.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadByteReads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. (Inherited from Stream.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSeekThis property is not supported and always throws a NotSupportedException. (Overrides Stream.Seek(Int64, SeekOrigin).)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSetLengthThis property is not supported and always throws a NotSupportedException. (Overrides Stream.SetLength(Int64).)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsWriteWrites compressed bytes to the underlying stream from the specified byte array. (Overrides Stream.Write(Byte[], Int32, Int32).)
Public methodSupported in .NET for Windows Store appsWriteAsync(Byte[], Int32, Int32)Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. (Inherited from Stream.)
Public methodSupported in .NET for Windows Store appsWriteAsync(Byte[], Int32, Int32, CancellationToken)Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests. (Inherited from Stream.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsWriteByteWrites a byte to the current position in the stream and advances the position within the stream by one byte. (Inherited from Stream.)
Top

  NameDescription
Public Extension MethodSupported in .NET for Windows Store appsAsInputStreamConverts a managed stream in the .NET for Windows Store apps to an input stream in the Windows Runtime. (Defined by WindowsRuntimeStreamExtensions.)
Public Extension MethodSupported in .NET for Windows Store appsAsOutputStreamConverts a managed stream in the .NET for Windows Store apps to an output stream in the Windows Runtime. (Defined by WindowsRuntimeStreamExtensions.)
Top

This class represents the gzip data format, which uses an industry-standard algorithm for lossless file compression and decompression. The format includes a cyclic redundancy check value for detecting data corruption. The gzip data format uses the same algorithm as the DeflateStream class, but can be extended to use other compression formats. The format can be readily implemented in a manner not covered by patents.

Starting with the .NET Framework 4.5, the DeflateStream class uses the zlib library for compression. As a result, it provides a better compression algorithm and, in most cases, a smaller compressed file than it provides in earlier versions of the .NET Framework.

Compressed GZipStream objects written to a file with an extension of .gz can be decompressed using many common compression tools; however, this class does not inherently provide functionality for adding files to or extracting files from zip archives.

The compression functionality in DeflateStream and GZipStream is exposed as a stream. Data is read on a byte-by-byte basis, so it is not possible to perform multiple passes to determine the best method for compressing entire files or large blocks of data. The DeflateStream and GZipStream classes are best used on uncompressed sources of data. If the source data is already compressed, using these classes may actually increase the size of the stream.

Notes to Inheritors

When you inherit from GZipStream, you must override the following members: CanSeek, CanWrite, and CanRead.

The following example shows how to use the GZipStream class to compress and decompress a directory of files.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft