|
| GZipStream (System.IO.Stream stream, CompressionMode mode) |
| Create a GZipStream using the specified CompressionMode. More...
|
|
| GZipStream (System.IO.Stream stream, CompressionMode mode, CompressionLevel level) |
| Create a GZipStream using the specified CompressionMode and the specified CompressionLevel. More...
|
|
| GZipStream (System.IO.Stream stream, CompressionMode mode, bool leaveOpen) |
| Create a GZipStream using the specified CompressionMode, and explicitly specify whether the stream should be left open after Deflation or Inflation. More...
|
|
| GZipStream (System.IO.Stream stream, CompressionMode mode, CompressionLevel level, bool leaveOpen) |
| 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. More...
|
|
override void | Close () |
| Close the stream. More...
|
|
override void | Flush () |
| Flush the stream. More...
|
|
override int | Read (byte[] buffer, int offset, int count) |
| Read and decompress data from the source stream. More...
|
|
override long | Seek (long offset, System.IO.SeekOrigin origin) |
| Calling this method always throws a NotImplementedException. More...
|
|
override void | SetLength (long value) |
| Calling this method always throws a NotImplementedException. More...
|
|
override void | Write (byte[] buffer, int offset, int count) |
| Write data to the stream. More...
|
|
|
String | FileName [get, set] |
| The FileName for the GZIP stream. More...
|
|
int | Crc32 [get] |
| The CRC on the GZIP stream. More...
|
|
virtual int | FlushMode [get, set] |
| This property sets the flush behavior on the stream. Sorry, though, not sure exactly how to describe all the various settings. More...
|
|
int | BufferSize [get, set] |
| Callers can set the buffer size of the working buffer with this property. More...
|
|
virtual long | TotalIn [get] |
| Returns the total number of bytes input so far. More...
|
|
virtual long | TotalOut [get] |
| Returns the total number of bytes output so far. More...
|
|
override bool | CanRead [get] |
| Indicates whether the stream can be read. More...
|
|
override bool | CanSeek [get] |
| Indicates whether the stream supports Seek operations. More...
|
|
override bool | CanWrite [get] |
| Indicates whether the stream can be written. More...
|
|
override long | Length [get] |
| Reading this property always throws a NotImplementedException. More...
|
|
override long | Position [get, set] |
| Reading or Writing this property always throws a NotImplementedException. More...
|
|
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.
- See also
- DeflateStream, ZlibStream
UniExtensions.Zlib.GZipStream.GZipStream |
( |
System.IO.Stream |
stream, |
|
|
CompressionMode |
mode, |
|
|
bool |
leaveOpen |
|
) |
| |
|
inline |
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.
- Parameters
-
stream | The stream which will be read or written. This is called the "captive" stream in other places in this documentation. |
mode | Indicates whether the GZipStream will compress or decompress. |
leaveOpen | true if the application would like the base stream to remain open after inflation/deflation. |
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().
This example shows how to use a DeflateStream to compress data.
using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
{
using (var raw = System.IO.File.Create(outputFile))
{
{
byte[] buffer = new byte[WORKING_BUFFER_SIZE];
int n= -1;
while (n != 0)
{
if (n > 0)
compressor.Write(buffer, 0, n);
n= input.Read(buffer, 0, buffer.Length);
}
}
}
}
Dim outputFile As String = (fileToCompress & ".compressed")
Using input As Stream = File.OpenRead(fileToCompress)
Using raw As FileStream = File.Create(outputFile)
Dim buffer As Byte() = New Byte(4096) {}
Dim n As Integer = -1
Do While (n <> 0)
If (n > 0) Then
compressor.Write(buffer, 0, n)
End If
n = input.Read(buffer, 0, buffer.Length)
Loop
End Using
End Using
End Using
- Parameters
-
stream | The stream which will be read or written. |
mode | Indicates whether the GZipStream will compress or decompress. |
leaveOpen | true if the application would like the stream to remain open after inflation/deflation. |
level | A tuning knob to trade speed for effectiveness. |