C# 클래스 NetWrok.HTTP.Zlib.GZipStream

A class for compressing and decompressing GZIP streams.

Like the GZipStream in the .NET Base Class Library, the Ionic.Zlib.GZipStream can compress while writing, or decompress while reading, but not vice versa.

A GZipStream can be used for Read() or Write(), and thus decompression or compression, but not both.

If you wish to use the GZipStream to compress (deflate) data, you must wrap it around a write-able stream. As you call Write() on the GZipStream, the data will be compressed into the GZIP (IETF RFC 1952) format.

If you want to decompress (inflate) data, you must wrap the GZipStream around a readable stream that contains an IETF RFC 1952-compliant stream. The data will be decompressed as you call Read() on the GZipStream.

Though the GZIP format allows data from multiple files to be concatenated together, this stream handles only a single segment of GZIP format, typically representing a single file.

For more information on GZIP, see IETF RFC 1952, "GZIP file format specification version 4.3".

This class is similar to ZlibStream and DeflateStream. ZlibStream handles RFC1950-compliant streams. DeflateStream handles RFC1951-compliant streams. And this class handles RFC1952-compliant streams.

상속: System.IO.Stream
파일 보기 프로젝트 열기: simonwittber/netwrok-client 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
Comment String
LastModified DateTime?

공개 메소드들

메소드 설명
Close ( ) : void

Close the stream.

This may or may not close the captive stream. See the ctor's with leaveOpen parameters for more information.

Flush ( ) : void

Flush the stream.

GZipStream ( System stream, CompressionMode mode ) : System

Create a GZipStream using the specified CompressionMode.

The GZipStream will use the default compression level.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

GZipStream ( System stream, CompressionMode mode, CompressionLevel level ) : System

Create a GZipStream using the specified CompressionMode and the specified CompressionLevel.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

GZipStream ( System stream, CompressionMode mode, CompressionLevel level, bool leaveOpen ) : System

Create a GZipStream using the specified CompressionMode and the specified CompressionLevel, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, after Close() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

GZipStream ( System stream, CompressionMode mode, bool leaveOpen ) : System

Create a GZipStream using the specified CompressionMode, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, after Close() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

The DeflateStream will use the default compression level.

See the other overloads of this constructor for example code.

Read ( byte buffer, int offset, int count ) : int

Read and decompress data from the source stream.

With a GZipStream, decompression is done through reading.

Seek ( long offset, System origin ) : long

Calling this method always throws a NotImplementedException.

SetLength ( long value ) : void

Calling this method always throws a NotImplementedException.

Write ( byte buffer, int offset, int count ) : void

Write data to the stream.

If you wish to use the GZipStream to compress data while writing, you can create a GZipStream with CompressionMode.Compress, and a writable output stream. Then call Write() on that GZipStream, providing uncompressed data as input. The data sent to the output stream will be the compressed form of the data written. If you wish to use the DeflateStream to decompress data while writing, you can create a GZipStream with CompressionMode.Decompress, and a writable output stream. Then call Write() on that stream, providing previously compressed data. The data sent to the output stream will be the decompressed form of the data written.

A GZipStream can be used for Read() or Write(), but not both.

비공개 메소드들

메소드 설명
EmitHeader ( ) : void
SlurpHeader ( byte buffer, int offset ) : int
SlurpZeroTerminatedString ( byte buffer, int offset, int &count ) : string

메소드 상세

Close() 공개 메소드

Close the stream.
This may or may not close the captive stream. See the ctor's with leaveOpen parameters for more information.
public Close ( ) : void
리턴 void

Flush() 공개 메소드

Flush the stream.
public Flush ( ) : void
리턴 void

GZipStream() 공개 메소드

Create a GZipStream using the specified CompressionMode.

The GZipStream will use the default compression level.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

public GZipStream ( System stream, CompressionMode mode ) : System
stream System The stream which will be read or written.
mode CompressionMode Indicates whether the GZipStream will compress or decompress.
리턴 System

GZipStream() 공개 메소드

Create a GZipStream using the specified CompressionMode and the specified CompressionLevel.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

public GZipStream ( System stream, CompressionMode mode, CompressionLevel level ) : System
stream System The stream to be read or written while deflating or inflating.
mode CompressionMode Indicates whether the GZipStream will compress or decompress.
level CompressionLevel A tuning knob to trade speed for effectiveness.
리턴 System

GZipStream() 공개 메소드

Create a GZipStream using the specified CompressionMode and the specified CompressionLevel, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, after Close() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

public GZipStream ( System stream, CompressionMode mode, CompressionLevel level, bool leaveOpen ) : System
stream System The stream which will be read or written.
mode CompressionMode Indicates whether the GZipStream will compress or decompress.
level CompressionLevel A tuning knob to trade speed for effectiveness.
leaveOpen bool true if the application would like the stream to remain open after inflation/deflation.
리턴 System

GZipStream() 공개 메소드

Create a GZipStream using the specified CompressionMode, and explicitly specify whether the stream should be left open after Deflation or Inflation.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, after Close() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it. Specify true for the leaveOpen parameter to leave the stream open.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

The DeflateStream will use the default compression level.

See the other overloads of this constructor for example code.

public GZipStream ( System stream, CompressionMode mode, bool leaveOpen ) : System
stream System The stream which will be read or written. This is called the /// "captive" stream in other places in this documentation.
mode CompressionMode Indicates whether the GZipStream will compress or decompress.
leaveOpen bool true if the application would like the base stream to remain open after inflation/deflation.
리턴 System

Read() 공개 메소드

Read and decompress data from the source stream.
With a GZipStream, decompression is done through reading.
public Read ( byte buffer, int offset, int count ) : int
buffer byte The buffer into which the decompressed data should be placed.
offset int the offset within that data array to put the first byte read.
count int the number of bytes to read.
리턴 int

Seek() 공개 메소드

Calling this method always throws a NotImplementedException.
public Seek ( long offset, System origin ) : long
offset long this is irrelevant, since it will always throw!
origin System this is irrelevant, since it will always throw!
리턴 long

SetLength() 공개 메소드

Calling this method always throws a NotImplementedException.
public SetLength ( long value ) : void
value long this is irrelevant, since it will always throw!
리턴 void

Write() 공개 메소드

Write data to the stream.

If you wish to use the GZipStream to compress data while writing, you can create a GZipStream with CompressionMode.Compress, and a writable output stream. Then call Write() on that GZipStream, providing uncompressed data as input. The data sent to the output stream will be the compressed form of the data written. If you wish to use the DeflateStream to decompress data while writing, you can create a GZipStream with CompressionMode.Decompress, and a writable output stream. Then call Write() on that stream, providing previously compressed data. The data sent to the output stream will be the decompressed form of the data written.

A GZipStream can be used for Read() or Write(), but not both.

public Write ( byte buffer, int offset, int count ) : void
buffer byte The buffer holding data to write to the stream.
offset int the offset within that data array to find the first byte to write.
count int the number of bytes to write.
리턴 void

프로퍼티 상세

Comment 공개적으로 프로퍼티

The Comment on the GZIP stream.
The GZIP format allows for each file to have an associated comment stored with the file. The comment is encoded with the ISO-8859-1 code page. To include a comment in a GZIP stream you create, set this Comment before calling Write() for the first time on the GZipStream. When using GZipStream to decompress, you can retrieve this comment after the first call to Read().
public String Comment
리턴 String

LastModified 공개적으로 프로퍼티

The last modified time for the GZIP stream.
GZIP allows the storage of a last modified time with each GZIP entry. When compressing data, you can set this before the first call to Write(). When decompressing, you can retrieve this value any time after the first call to Read().
public DateTime? LastModified
리턴 DateTime?