DeflateStream Class

Provides methods and properties for compressing and decompressing streams using the Deflate algorithm.

System.Object
  System.MarshalByRefObject
    System.IO.Stream
      System.IO.Compression.DeflateStream

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

type DeflateStream =  
    class
        inherit Stream
    end

The DeflateStream type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkDeflateStream(Stream, CompressionMode)Initializes a new instance of the DeflateStream class using the specified stream and CompressionMode value.
Public methodSupported by the XNA FrameworkDeflateStream(Stream, CompressionMode, Boolean)Initializes a new instance of the DeflateStream class using the specified stream and CompressionMode value, and a value that specifies whether to leave the stream open.
Top

  NameDescription
Public propertySupported by the XNA FrameworkBaseStreamGets a reference to the underlying stream.
Public propertySupported by the XNA FrameworkCanReadGets a value indicating whether the stream supports reading while decompressing a file. (Overrides Stream.CanRead.)
Public propertySupported by the XNA FrameworkCanSeekGets a value indicating whether the stream supports seeking. (Overrides Stream.CanSeek.)
Public propertySupported by the XNA FrameworkCanTimeoutGets a value that determines whether the current stream can time out. (Inherited from Stream.)
Public propertySupported by the XNA FrameworkCanWriteGets a value indicating whether the stream supports writing. (Overrides Stream.CanWrite.)
Public propertySupported by the XNA FrameworkLengthThis property is not supported and always throws a NotSupportedException. (Overrides Stream.Length.)
Public propertySupported by the XNA FrameworkPositionThis property is not supported and always throws a NotSupportedException. (Overrides Stream.Position.)
Public propertySupported by the XNA FrameworkReadTimeoutGets 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 FrameworkWriteTimeoutGets 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 FrameworkBeginReadBegins an asynchronous read operation. (Overrides Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).)
Public methodSupported by the XNA FrameworkBeginWriteBegins an asynchronous write operation. (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. (Inherited from Stream.)
Public methodCopyTo(Stream)Reads the bytes from the current stream and writes them to the destination stream. (Inherited from Stream.)
Public methodCopyTo(Stream, Int32)Reads all the bytes from the current stream and writes them to a destination stream, using a specified buffer size. (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 FrameworkDispose()Releases all resources used by the Stream. (Inherited from Stream.)
Protected methodSupported by the XNA FrameworkDispose(Boolean)Releases the unmanaged resources used by the DeflateStream and optionally releases the managed resources. (Overrides Stream.Dispose(Boolean).)
Public methodSupported by the XNA FrameworkEndReadWaits for the pending asynchronous read to complete. (Overrides Stream.EndRead(IAsyncResult).)
Public methodSupported by the XNA FrameworkEndWriteEnds an asynchronous write operation. (Overrides Stream.EndWrite(IAsyncResult).)
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows 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 FrameworkFlushFlushes the contents of the internal buffer of the current stream object to the underlying stream. (Overrides Stream.Flush().)
Public methodSupported by the XNA FrameworkGetHashCodeServes as a hash function for a particular type. (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 FrameworkGetTypeGets 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 FrameworkMemberwiseClone()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. Provides support for a Contract. (Inherited from Stream.)
Public methodSupported by the XNA FrameworkReadReads a number of decompressed bytes into the specified byte array. (Overrides Stream.Read(Byte[], Int32, Int32).)
Public methodSupported by the XNA FrameworkReadByteReads 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 FrameworkSeekThis operation is not supported and always throws a NotSupportedException. (Overrides Stream.Seek(Int64, SeekOrigin).)
Public methodSupported by the XNA FrameworkSetLengthThis operation is not supported and always throws a NotSupportedException. (Overrides Stream.SetLength(Int64).)
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkWriteWrites compressed bytes to the underlying stream from the specified byte array. (Overrides Stream.Write(Byte[], Int32, Int32).)
Public methodSupported by the XNA FrameworkWriteByteWrites a byte to the current position in the stream and advances the position within the stream by one byte. (Inherited from Stream.)
Top

This class represents the Deflate algorithm, an industry standard algorithm for lossless file compression and decompression. It uses a combination of the LZ77 algorithm and Huffman coding. Data can be produced or consumed, even for an arbitrarily long, sequentially presented input data stream, using only previously bound amount of intermediate storage. The format can be implemented readily in a manner not covered by patents. For more information, see RFC 1951. "DEFLATE Compressed Data Format Specification version 1.3."

This class does not inherently provide functionality for adding files to or extracting files from .zip archives.

The GZipStream class uses the gzip data format, which includes a cyclic redundancy check value for detecting data corruption. The gzip data format uses the same compression algorithm as the DeflateStream class.

The compression functionality in DeflateStream and GZipStream is exposed as a stream. Data is read in 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.

The following example shows how to use the DeflateStream 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, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft