ICSharpCode::SharpZipLib::Zip::ZipFile Class Reference

This class represents a Zip archive. You can ask for the contained entries, or get an input stream for a file entry. The entry is automatically decompressed. More...

List of all members.

Public Member Functions

delegate void KeysRequiredEventHandler (object sender, KeysRequiredEventArgs e)
 Delegate for handling keys/password setting during compresion/decompression.
 ZipFile (string name)
 Opens a Zip file with the given name for reading.
 ZipFile (FileStream file)
 Opens a Zip file reading the given FileStream.
 ZipFile (Stream baseStream)
 Opens a Zip file reading the given Stream.
void Close ()
 Closes the ZipFile. If the stream is IsStreamOwnerowned then this also closes the underlying input stream. Once closed, no further instance methods should be called.
IEnumerator GetEnumerator ()
 Returns an enumerator for the Zip entries in this Zip file.
int FindEntry (string name, bool ignoreCase)
 Return the index of the entry with a matching name.
ZipEntry GetEntry (string name)
 Searches for a zip entry in this archive with the given name. String comparisons are case insensitive.
bool TestArchive (bool testData)
 Test an archive for integrity/validity.
Stream GetInputStream (ZipEntry entry)
 Creates an input stream reading the given zip entry as uncompressed data. Normally zip entry should be an entry returned by GetEntry().
Stream GetInputStream (int entryIndex)
 Creates an input stream reading a zip entry.

Public Attributes

KeysRequiredEventHandler KeysRequired
 Event handler for handling encryption keys.

Properties

byte[] Key
 Get/set the encryption key value.
string Password
 Password to be used for encrypting/decrypting files.
byte[] iv = null
bool HaveKeys
bool IsStreamOwner
 Get/set a flag indicating if the underlying stream is owned by the ZipFile instance. If the flag is true then the stream will be closed when CloseClose is called.
ZipEntry this [int index]
 Indexer property for ZipEntries.
string ZipFileComment
 Gets the comment for the zip file.
string Name
 Gets the name of this zip file.
int Size
 Gets the number of entries in this zip file.

Private Member Functions

void OnKeysRequired (string fileName)
 Handles getting of encryption keys when required.
int ReadLeShort ()
 Read an unsigned short in little endian byte order.
int ReadLeInt ()
 Read an int in little endian byte order.
long LocateBlockWithSignature (int signature, long endLocation, int minimumBlockSize, int maximumVariableData)
void ReadEntries ()
 Search for and read the central directory of a zip file filling the entries array. This is called exactly once by the constructors.
long TestLocalHeader (ZipEntry entry, bool fullTest, bool extractTest)
 Test the local header against that provided from the central directory.
long CheckLocalHeader (ZipEntry entry)
 Checks, if the local header of the entry at index i matches the central directory, and returns the offset to the data.
void ReadFully (Stream s, byte[] outBuf)
void CheckClassicPassword (CryptoStream classicCryptoStream, ZipEntry entry)
Stream CreateAndInitDecryptionStream (Stream baseStream, ZipEntry entry)
void WriteEncryptionHeader (Stream stream, long crcValue)
Stream CreateAndInitEncryptionStream (Stream baseStream, ZipEntry entry)
Stream GetOutputStream (ZipEntry entry, string fileName)
 Gets an output stream for the specified ZipEntry.

Private Attributes

string name
string comment
Stream baseStream
bool isStreamOwner = true
long offsetOfFirstEntry = 0
ZipEntry[] entries
byte[] key = null

Classes

class  PartialInputStream
class  ZipEntryEnumeration


Detailed Description

This class represents a Zip archive. You can ask for the contained entries, or get an input stream for a file entry. The entry is automatically decompressed.

This class is thread safe: You can open input streams for arbitrary entries in different threads.

Author of the original java version : Jochen Hoenicke

            using System;
            using System.Text;
            using System.Collections;
            using System.IO;
            
            using ICSharpCode.SharpZipLib.Zip;
            
            class MainClass
            {
                static public void Main(string[] args)
                {
                        ZipFile zFile = new ZipFile(args[0]);
                        Console.WriteLine("Listing of : " + zFile.Name);
                        Console.WriteLine("");
                        Console.WriteLine("Raw Size    Size      Date     Time     Name");
                        Console.WriteLine("--------  --------  --------  ------  ---------");
                        foreach (ZipEntry e in zFile) {
                                DateTime d = e.DateTime;
                                Console.WriteLine("{0, -10}{1, -10}{2}  {3}   {4}", e.Size, e.CompressedSize,
                                                                                    d.ToString("dd-MM-yy"), d.ToString("t"),
                                                                                    e.Name);
                        }
                }
            }

Definition at line 139 of file ZipFile.cs.


Constructor & Destructor Documentation

ICSharpCode::SharpZipLib::Zip::ZipFile::ZipFile string  name  )  [inline]
 

Opens a Zip file with the given name for reading.

Exceptions:
IOException An i/o error occurs
ZipException The file doesn't contain a valid zip archive.

Definition at line 221 of file ZipFile.cs.

ICSharpCode::SharpZipLib::Zip::ZipFile::ZipFile FileStream  file  )  [inline]
 

Opens a Zip file reading the given FileStream.

Exceptions:
IOException An i/o error occurs.
ZipException The file doesn't contain a valid zip archive.

Definition at line 243 of file ZipFile.cs.

ICSharpCode::SharpZipLib::Zip::ZipFile::ZipFile Stream  baseStream  )  [inline]
 

Opens a Zip file reading the given Stream.

Exceptions:
IOException An i/o error occurs
ZipException The file doesn't contain a valid zip archive.
The stream provided cannot seek

Definition at line 266 of file ZipFile.cs.


Member Function Documentation

void ICSharpCode::SharpZipLib::Zip::ZipFile::CheckClassicPassword CryptoStream  classicCryptoStream,
ZipEntry  entry
[inline, private]
 

Definition at line 687 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Zip::ZipEntry::Crc, ICSharpCode::SharpZipLib::Zip::ZipEntry::DosTime, and ICSharpCode::SharpZipLib::Zip::ZipEntry::Flags.

long ICSharpCode::SharpZipLib::Zip::ZipFile::CheckLocalHeader ZipEntry  entry  )  [inline, private]
 

Checks, if the local header of the entry at index i matches the central directory, and returns the offset to the data.

Returns:
The start offset of the (compressed) data.
Exceptions:
System.IO.EndOfStreamException The stream ends prematurely
ICSharpCode.SharpZipLib.Zip.ZipException The local header signature is invalid, the entry and central header file name lengths are different or the local and entry compression methods dont match

Definition at line 667 of file ZipFile.cs.

void ICSharpCode::SharpZipLib::Zip::ZipFile::Close  )  [inline]
 

Closes the ZipFile. If the stream is IsStreamOwnerowned then this also closes the underlying input stream. Once closed, no further instance methods should be called.

Exceptions:
System.IO.IOException An i/o error occurs.

Definition at line 469 of file ZipFile.cs.

Stream ICSharpCode::SharpZipLib::Zip::ZipFile::CreateAndInitDecryptionStream Stream  baseStream,
ZipEntry  entry
[inline, private]
 

Definition at line 704 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Encryption::PkzipClassicManaged::CreateDecryptor(), ICSharpCode::SharpZipLib::Zip::ZipEntry::Flags, ICSharpCode::SharpZipLib::Zip::ZipEntry::Name, and ICSharpCode::SharpZipLib::Zip::ZipEntry::Version.

Stream ICSharpCode::SharpZipLib::Zip::ZipFile::CreateAndInitEncryptionStream Stream  baseStream,
ZipEntry  entry
[inline, private]
 

Definition at line 736 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Zip::ZipEntry::Crc, ICSharpCode::SharpZipLib::Encryption::PkzipClassicManaged::CreateEncryptor(), ICSharpCode::SharpZipLib::Zip::ZipEntry::DosTime, ICSharpCode::SharpZipLib::Zip::ZipEntry::Flags, ICSharpCode::SharpZipLib::Zip::ZipEntry::Name, and ICSharpCode::SharpZipLib::Zip::ZipEntry::Version.

int ICSharpCode::SharpZipLib::Zip::ZipFile::FindEntry string  name,
bool  ignoreCase
[inline]
 

Return the index of the entry with a matching name.

Parameters:
name Entry name to find
ignoreCase If true the comparison is case insensitive
Returns:
The index position of the matching entry or -1 if not found
Exceptions:
InvalidOperationException The Zip file has been closed.

Definition at line 503 of file ZipFile.cs.

ZipEntry ICSharpCode::SharpZipLib::Zip::ZipFile::GetEntry string  name  )  [inline]
 

Searches for a zip entry in this archive with the given name. String comparisons are case insensitive.

Parameters:
name The name to find. May contain directory components separated by slashes ('/').
Returns:
The zip entry, or null if no entry with that name exists.
Exceptions:
InvalidOperationException The Zip file has been closed.

Definition at line 540 of file ZipFile.cs.

IEnumerator ICSharpCode::SharpZipLib::Zip::ZipFile::GetEnumerator  )  [inline]
 

Returns an enumerator for the Zip entries in this Zip file.

Exceptions:
InvalidOperationException The Zip file has been closed.

Definition at line 485 of file ZipFile.cs.

Stream ICSharpCode::SharpZipLib::Zip::ZipFile::GetInputStream int  entryIndex  )  [inline]
 

Creates an input stream reading a zip entry.

Parameters:
entryIndex The index of the entry to obtain an input stream for.
Returns:
An input stream.
Exceptions:
InvalidOperationException The ZipFile has already been closed
ICSharpCode.SharpZipLib.Zip.ZipException The compression method for the entry is unknown
IndexOutOfRangeException The entry is not found in the ZipFile

Definition at line 839 of file ZipFile.cs.

Stream ICSharpCode::SharpZipLib::Zip::ZipFile::GetInputStream ZipEntry  entry  )  [inline]
 

Creates an input stream reading the given zip entry as uncompressed data. Normally zip entry should be an entry returned by GetEntry().

Returns:
the input stream.
Exceptions:
InvalidOperationException The ZipFile has already been closed
ICSharpCode.SharpZipLib.Zip.ZipException The compression method for the entry is unknown
IndexOutOfRangeException The entry is not found in the ZipFile

Definition at line 807 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Zip::ZipEntry::Name, and ICSharpCode::SharpZipLib::Zip::ZipEntry::ZipFileIndex.

Stream ICSharpCode::SharpZipLib::Zip::ZipFile::GetOutputStream ZipEntry  entry,
string  fileName
[inline, private]
 

Gets an output stream for the specified ZipEntry.

Parameters:
entry The entry to get an outputstream for.
fileName 
Returns:
The output stream obtained for the entry.

Definition at line 765 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Zip::ZipEntry::CompressionMethod, and ICSharpCode::SharpZipLib::Zip::ZipEntry::IsCrypted.

delegate void ICSharpCode::SharpZipLib::Zip::ZipFile::KeysRequiredEventHandler object  sender,
KeysRequiredEventArgs  e
 

Delegate for handling keys/password setting during compresion/decompression.

long ICSharpCode::SharpZipLib::Zip::ZipFile::LocateBlockWithSignature int  signature,
long  endLocation,
int  minimumBlockSize,
int  maximumVariableData
[inline, private]
 

Definition at line 324 of file ZipFile.cs.

void ICSharpCode::SharpZipLib::Zip::ZipFile::OnKeysRequired string  fileName  )  [inline, private]
 

Handles getting of encryption keys when required.

Parameters:
fileName The file for which encryptino keys are required.

Definition at line 167 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Zip::KeysRequiredEventArgs::Key.

void ICSharpCode::SharpZipLib::Zip::ZipFile::ReadEntries  )  [inline, private]
 

Search for and read the central directory of a zip file filling the entries array. This is called exactly once by the constructors.

Exceptions:
System.IO.IOException An i/o error occurs.
ICSharpCode.SharpZipLib.Zip.ZipException The central directory is malformed or cannot be found

Definition at line 355 of file ZipFile.cs.

void ICSharpCode::SharpZipLib::Zip::ZipFile::ReadFully Stream  s,
byte[]  outBuf
[inline, private]
 

Definition at line 673 of file ZipFile.cs.

int ICSharpCode::SharpZipLib::Zip::ZipFile::ReadLeInt  )  [inline, private]
 

Read an int in little endian byte order.

Returns:
Returns the value read.
Exceptions:
IOException An i/o error occurs.
System.IO.EndOfStreamException The file ends prematurely

Definition at line 318 of file ZipFile.cs.

int ICSharpCode::SharpZipLib::Zip::ZipFile::ReadLeShort  )  [inline, private]
 

Read an unsigned short in little endian byte order.

Returns:
Returns the value read.
Exceptions:
IOException An i/o error occurs.
EndOfStreamException The file ends prematurely

Definition at line 303 of file ZipFile.cs.

bool ICSharpCode::SharpZipLib::Zip::ZipFile::TestArchive bool  testData  )  [inline]
 

Test an archive for integrity/validity.

Parameters:
testData Perform low level data Crc check
Returns:
true iff the test passes, false otherwise

Definition at line 554 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Checksums::Crc32::Update(), and ICSharpCode::SharpZipLib::Checksums::Crc32::Value.

long ICSharpCode::SharpZipLib::Zip::ZipFile::TestLocalHeader ZipEntry  entry,
bool  fullTest,
bool  extractTest
[inline, private]
 

Test the local header against that provided from the central directory.

Parameters:
entry The entry to test against
fullTest If true be extremely picky about the testing, otherwise be relaxed
extractTest Apply extra testing to see if the entry can be extracted by the library
Returns:
The offset of the entries data in the file

Definition at line 597 of file ZipFile.cs.

References ICSharpCode::SharpZipLib::Zip::ZipEntry::CompressionMethod, ICSharpCode::SharpZipLib::Zip::ZipEntry::Crc, ICSharpCode::SharpZipLib::Zip::ZipEntry::Flags, ICSharpCode::SharpZipLib::Zip::ZipEntry::Name, and ICSharpCode::SharpZipLib::Zip::ZipEntry::Offset.

void ICSharpCode::SharpZipLib::Zip::ZipFile::WriteEncryptionHeader Stream  stream,
long  crcValue
[inline, private]
 

Definition at line 727 of file ZipFile.cs.


Member Data Documentation

Stream ICSharpCode::SharpZipLib::Zip::ZipFile::baseStream [private]
 

Definition at line 143 of file ZipFile.cs.

string ICSharpCode::SharpZipLib::Zip::ZipFile::comment [private]
 

Definition at line 142 of file ZipFile.cs.

ZipEntry [] ICSharpCode::SharpZipLib::Zip::ZipFile::entries [private]
 

Definition at line 146 of file ZipFile.cs.

bool ICSharpCode::SharpZipLib::Zip::ZipFile::isStreamOwner = true [private]
 

Definition at line 144 of file ZipFile.cs.

byte [] ICSharpCode::SharpZipLib::Zip::ZipFile::key = null [private]
 

Definition at line 176 of file ZipFile.cs.

KeysRequiredEventHandler ICSharpCode::SharpZipLib::Zip::ZipFile::KeysRequired
 

Event handler for handling encryption keys.

Definition at line 161 of file ZipFile.cs.

string ICSharpCode::SharpZipLib::Zip::ZipFile::name [private]
 

Definition at line 141 of file ZipFile.cs.

long ICSharpCode::SharpZipLib::Zip::ZipFile::offsetOfFirstEntry = 0 [private]
 

Definition at line 145 of file ZipFile.cs.


Property Documentation

bool ICSharpCode::SharpZipLib::Zip::ZipFile::HaveKeys [get, private]
 

Definition at line 207 of file ZipFile.cs.

bool ICSharpCode::SharpZipLib::Zip::ZipFile::IsStreamOwner [get, set, private]
 

Get/set a flag indicating if the underlying stream is owned by the ZipFile instance. If the flag is true then the stream will be closed when CloseClose is called.

The default value is true in all cases.

Definition at line 288 of file ZipFile.cs.

byte [] ICSharpCode::SharpZipLib::Zip::ZipFile::iv = null [private]
 

Definition at line 204 of file ZipFile.cs.

byte [] ICSharpCode::SharpZipLib::Zip::ZipFile::Key [get, set, private]
 

Get/set the encryption key value.

Definition at line 182 of file ZipFile.cs.

string ICSharpCode::SharpZipLib::Zip::ZipFile::Name [get]
 

Gets the name of this zip file.

Definition at line 879 of file ZipFile.cs.

string ICSharpCode::SharpZipLib::Zip::ZipFile::Password [set]
 

Password to be used for encrypting/decrypting files.

Set to null if no password is required.

Definition at line 192 of file ZipFile.cs.

int ICSharpCode::SharpZipLib::Zip::ZipFile::Size [get]
 

Gets the number of entries in this zip file.

Exceptions:
InvalidOperationException The Zip file has been closed.

Definition at line 891 of file ZipFile.cs.

ZipEntry ICSharpCode::SharpZipLib::Zip::ZipFile::this[int index] [get]
 

Indexer property for ZipEntries.

Definition at line 521 of file ZipFile.cs.

string ICSharpCode::SharpZipLib::Zip::ZipFile::ZipFileComment [get]
 

Gets the comment for the zip file.

Definition at line 870 of file ZipFile.cs.


The documentation for this class was generated from the following file:
Generated on Fri Jun 23 21:50:06 2006 for OblivionModTranslator by  doxygen 1.4.6-NO