Class GZipOutputStream
This filter stream is used to compress a stream into a "GZIP" stream. The "GZIP" format is described in RFC 1952.
author of the original java version : John Leuner
Inheritance
Implements
Inherited Members
Namespace: ICSharpCode.SharpZipLib.GZip
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class GZipOutputStream : DeflaterOutputStream, IDisposable
Examples
This sample shows how to gzip a file
using System;
using System.IO;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Core;
class MainClass
{
public static void Main(string[] args)
{
using (Stream s = new GZipOutputStream(File.Create(args[0] + ".gz")))
using (FileStream fs = File.OpenRead(args[0])) {
byte[] writeData = new byte[4096];
Streamutils.Copy(s, fs, writeData);
}
}
}
}
Constructors
| Improve this Doc View SourceGZipOutputStream(Stream)
Creates a GzipOutputStream with the default buffer size
Declaration
public GZipOutputStream(Stream baseOutputStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | baseOutputStream | The stream to read data (to be compressed) from |
GZipOutputStream(Stream, Int32)
Creates a GZipOutputStream with the specified buffer size
Declaration
public GZipOutputStream(Stream baseOutputStream, int size)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | baseOutputStream | The stream to read data (to be compressed) from |
System.Int32 | size | Size of the buffer to use |
Fields
| Improve this Doc View Sourcecrc
CRC-32 value for uncompressed data
Declaration
protected Crc32 crc
Field Value
Type | Description |
---|---|
Crc32 |
Properties
| Improve this Doc View SourceFileName
Original filename
Declaration
public string FileName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceDispose(Boolean)
Writes remaining compressed output data to the output stream and closes it.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
| Improve this Doc View SourceFinish()
Finish compression and write any footer information required to stream
Declaration
public override void Finish()
Overrides
| Improve this Doc View SourceFinishAsync(CancellationToken)
Finish compression and write any footer information required to stream
Declaration
public override async Task FinishAsync(CancellationToken ct)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | ct |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
| Improve this Doc View SourceFlush()
Flushes the stream by ensuring the header is written, and then calling Flush on the deflater.
Declaration
public override void Flush()
Overrides
| Improve this Doc View SourceFlushAsync(CancellationToken)
Flushes the stream by ensuring the header is written, and then calling Flush on the deflater.
Declaration
public override async Task FlushAsync(CancellationToken ct)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | ct |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
GetLevel()
Get the current compression level.
Declaration
public int GetLevel()
Returns
Type | Description |
---|---|
System.Int32 | The current compression level. |
SetLevel(Int32)
Sets the active compression level (0-9). The new level will be activated immediately.
Declaration
public void SetLevel(int level)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | level | The compression level to set. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Level specified is not supported. |
Write(Byte[], Int32, Int32)
Write given buffer to output updating crc
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | Buffer to write |
System.Int32 | offset | Offset of first byte in buf to write |
System.Int32 | count | Number of bytes to write |