Show / Hide Table of Contents

Class ZipInputStream

This is an InflaterInputStream that reads the files baseInputStream an zip archive one after another. It has a special method to get the zip entry of the next file. The zip entry contains information about the file name size, compressed size, Crc, etc. It includes support for Stored and Deflated entries.

Author of the original java version : Jochen Hoenicke

Inheritance
System.Object
System.MarshalByRefObject
System.IO.Stream
InflaterInputStream
ZipInputStream
Implements
System.IDisposable
Inherited Members
InflaterInputStream.IsStreamOwner
InflaterInputStream.Skip(Int64)
InflaterInputStream.StopDecrypting()
InflaterInputStream.Fill()
InflaterInputStream.CanRead
InflaterInputStream.CanSeek
InflaterInputStream.CanWrite
InflaterInputStream.Position
InflaterInputStream.Flush()
InflaterInputStream.Seek(Int64, SeekOrigin)
InflaterInputStream.SetLength(Int64)
InflaterInputStream.Write(Byte[], Int32, Int32)
InflaterInputStream.WriteByte(Byte)
InflaterInputStream.inf
InflaterInputStream.inputBuffer
InflaterInputStream.csize
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.FlushAsync(System.Threading.CancellationToken)
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.WriteAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
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.Zip
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class ZipInputStream : InflaterInputStream, IDisposable
Examples

This sample shows how to read a zip file

using System;
using System.Text;
using System.IO;

using ICSharpCode.SharpZipLib.Zip;

class MainClass
{
    public static void Main(string[] args)
    {
        using ( ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]))) {

            ZipEntry theEntry;
            const int size = 2048;
            byte[] data = new byte[2048];

            while ((theEntry = s.GetNextEntry()) != null) {
                if ( entry.IsFile ) {
                    Console.Write("Show contents (y/n) ?");
                    if (Console.ReadLine() == "y") {
                        while (true) {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0) {
                                Console.Write(new ASCIIEncoding().GetString(data, 0, size));
                            } else {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}

Constructors

| Improve this Doc View Source

ZipInputStream(Stream)

Creates a new Zip input stream, for reading a zip archive.

Declaration
public ZipInputStream(Stream baseInputStream)
Parameters
Type Name Description
System.IO.Stream baseInputStream

The underlying System.IO.Stream providing data.

| Improve this Doc View Source

ZipInputStream(Stream, StringCodec)

Creates a new Zip input stream, for reading a zip archive.

Declaration
public ZipInputStream(Stream baseInputStream, StringCodec stringCodec)
Parameters
Type Name Description
System.IO.Stream baseInputStream

The underlying System.IO.Stream providing data.

StringCodec stringCodec
| Improve this Doc View Source

ZipInputStream(Stream, Int32)

Creates a new Zip input stream, for reading a zip archive.

Declaration
public ZipInputStream(Stream baseInputStream, int bufferSize)
Parameters
Type Name Description
System.IO.Stream baseInputStream

The underlying System.IO.Stream providing data.

System.Int32 bufferSize

Size of the buffer.

Properties

| Improve this Doc View Source

Available

Returns 1 if there is an entry available Otherwise returns 0.

Declaration
public override int Available { get; }
Property Value
Type Description
System.Int32
Overrides
InflaterInputStream.Available
| Improve this Doc View Source

CanDecompressEntry

Gets a value indicating if there is a current entry and it can be decompressed

Declaration
public bool CanDecompressEntry { get; }
Property Value
Type Description
System.Boolean
Remarks

The entry can only be decompressed if the library supports the zip features required to extract it. See the ZipEntry Version property for more details.

Since ZipInputStream uses the local headers for extraction, entries with no compression combined with the Descriptor flag set, cannot be extracted as the end of the entry data cannot be deduced.

| Improve this Doc View Source

Length

Returns the current size that can be read from the current entry if available

Declaration
public override long Length { get; }
Property Value
Type Description
System.Int64
Overrides
InflaterInputStream.Length
Exceptions
Type Condition
ZipException

Thrown if the entry size is not known.

System.InvalidOperationException

Thrown if no entry is currently available.

| Improve this Doc View Source

Password

Optional password used for encryption when non-null

Declaration
public string Password { get; set; }
Property Value
Type Description
System.String

A password for all encrypted entries in this ZipInputStream

Methods

| Improve this Doc View Source

CloseEntry()

Closes the current zip entry and moves to the next one.

Declaration
public void CloseEntry()
Exceptions
Type Condition
System.InvalidOperationException

The stream is closed

ZipException

The Zip stream ends early

| Improve this Doc View Source

Dispose(Boolean)

Closes the zip input stream

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing
Overrides
InflaterInputStream.Dispose(Boolean)
| Improve this Doc View Source

GetNextEntry()

Advances to the next entry in the archive

Declaration
public ZipEntry GetNextEntry()
Returns
Type Description
ZipEntry

The next entry in the archive or null if there are no more entries.

Remarks

If the previous entry is still open CloseEntry is called.

Exceptions
Type Condition
System.InvalidOperationException

Input stream is closed

ZipException

Password is not set, password is invalid, compression method is invalid, version required to extract is not supported

| Improve this Doc View Source

Read(Byte[], Int32, Int32)

Read a block of bytes from the stream.

Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type Name Description
System.Byte[] buffer

The destination for the bytes.

System.Int32 offset

The index to start storing data.

System.Int32 count

The number of bytes to attempt to read.

Returns
Type Description
System.Int32

Returns the number of bytes read.

Overrides
InflaterInputStream.Read(Byte[], Int32, Int32)
Remarks

Zero bytes read means end of stream.

| Improve this Doc View Source

ReadByte()

Reads a byte from the current zip entry.

Declaration
public override int ReadByte()
Returns
Type Description
System.Int32

The byte or -1 if end of stream is reached.

Overrides
System.IO.Stream.ReadByte()

Implements

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