Show / Hide Table of Contents

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
System.Object
System.MarshalByRefObject
System.IO.Stream
DeflaterOutputStream
GZipOutputStream
Implements
System.IDisposable
Inherited Members
DeflaterOutputStream.IsStreamOwner
DeflaterOutputStream.CanPatchEntries
DeflaterOutputStream.cryptoTransform_
DeflaterOutputStream.AESAuthCode
DeflaterOutputStream.ZipCryptoEncoding
DeflaterOutputStream.EncryptBlock(Byte[], Int32, Int32)
DeflaterOutputStream.Deflate()
DeflaterOutputStream.CanRead
DeflaterOutputStream.CanSeek
DeflaterOutputStream.CanWrite
DeflaterOutputStream.Length
DeflaterOutputStream.Position
DeflaterOutputStream.Seek(Int64, SeekOrigin)
DeflaterOutputStream.SetLength(Int64)
DeflaterOutputStream.ReadByte()
DeflaterOutputStream.Read(Byte[], Int32, Int32)
DeflaterOutputStream.GetAuthCodeIfAES()
DeflaterOutputStream.WriteByte(Byte)
DeflaterOutputStream.deflater_
DeflaterOutputStream.baseOutputStream_
DeflaterOutputStream._stringCodec
System.IO.Stream.Null
System.IO.Stream.BeginRead(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.BeginWrite(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.Close()
System.IO.Stream.CopyTo(System.IO.Stream)
System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.CreateWaitHandle()
System.IO.Stream.Dispose()
System.IO.Stream.EndRead(System.IAsyncResult)
System.IO.Stream.EndWrite(System.IAsyncResult)
System.IO.Stream.FlushAsync()
System.IO.Stream.ObjectInvariant()
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.Synchronized(System.IO.Stream)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.CanTimeout
System.IO.Stream.ReadTimeout
System.IO.Stream.WriteTimeout
System.MarshalByRefObject.GetLifetimeService()
System.MarshalByRefObject.InitializeLifetimeService()
System.MarshalByRefObject.MemberwiseClone(System.Boolean)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
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 Source

GZipOutputStream(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

| Improve this Doc View Source

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 Source

crc

CRC-32 value for uncompressed data

Declaration
protected Crc32 crc
Field Value
Type Description
Crc32

Properties

| Improve this Doc View Source

FileName

Original filename

Declaration
public string FileName { get; set; }
Property Value
Type Description
System.String
| Improve this Doc View Source

ModifiedTime

If defined, will use this time instead of the current for the output header

Declaration
public DateTime? ModifiedTime { get; set; }
Property Value
Type Description
System.Nullable<System.DateTime>

Methods

| Improve this Doc View Source

Dispose(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
DeflaterOutputStream.Dispose(Boolean)
| Improve this Doc View Source

Finish()

Finish compression and write any footer information required to stream

Declaration
public override void Finish()
Overrides
DeflaterOutputStream.Finish()
| Improve this Doc View Source

FinishAsync(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
DeflaterOutputStream.FinishAsync(CancellationToken)
| Improve this Doc View Source

Flush()

Flushes the stream by ensuring the header is written, and then calling Flush on the deflater.

Declaration
public override void Flush()
Overrides
DeflaterOutputStream.Flush()
| Improve this Doc View Source

FlushAsync(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
DeflaterOutputStream.FlushAsync(CancellationToken)
| Improve this Doc View Source

GetLevel()

Get the current compression level.

Declaration
public int GetLevel()
Returns
Type Description
System.Int32

The current compression level.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

Overrides
DeflaterOutputStream.Write(Byte[], Int32, Int32)
| Improve this Doc View Source

WriteAsync(Byte[], Int32, Int32, CancellationToken)

Asynchronously write given buffer to output updating crc

Declaration
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken ct)
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

System.Threading.CancellationToken ct

The token to monitor for cancellation requests

Returns
Type Description
System.Threading.Tasks.Task
Overrides
DeflaterOutputStream.WriteAsync(Byte[], Int32, Int32, CancellationToken)

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000-2022 SharpZipLib Contributors