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
Implements
Inherited Members
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 SourceZipInputStream(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. |
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 |
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 SourceAvailable
Returns 1 if there is an entry available Otherwise returns 0.
Declaration
public override int Available { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
| Improve this Doc View SourceCanDecompressEntry
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.
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
Exceptions
Type | Condition |
---|---|
ZipException | Thrown if the entry size is not known. |
System.InvalidOperationException | Thrown if no entry is currently available. |
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 SourceCloseEntry()
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 |
Dispose(Boolean)
Closes the zip input stream
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
| Improve this Doc View SourceGetNextEntry()
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 |
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
Remarks
Zero bytes read means end of stream.
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. |