static void ListContents()
{
// Create a list to contain the zipped item names
List<string> filenames = new List<string>();
// TODO: Somehow obtain a stream to the source Zip file
using( Stream zipFileStream = ObtainZipFileStream() )
{
// Create a Zip reader object around the stream.
// Remember that ZipReader doesn't close the underlying stream given here
using( ZipReader zipReader = new ZipReader( zipFileStream ) )
{
// Optional. Provide the default password for encrypted items in the archive
zipReader.EncryptionPassword = "Password";
// Create a large buffer for speed
byte[] buffer = new byte[ 1024 * 1024 ];
ZipItemLocalHeader zipItemLocalHeader;
// While the reader finds local headers
while( ( zipItemLocalHeader = zipReader.ReadItemLocalHeader() ) != null )
{
// Add the filename to our list
filenames.Add( zipItemLocalHeader.FileName );
// Skip over the data using our buffer. This avoids recreating one each time
zipReader.ReadItemData( Stream.Null, buffer, 0, buffer.Length );
}
// Optional. Have the reader give us the zip ending header
ZipEndHeader endHeader = zipReader.ReadEndHeader();
// If the header contains a global zip comment
if( endHeader != null && !String.IsNullOrEmpty( endHeader.ZipComment ) )
{
// TODO: Do something with the global zip comment
}
}
}
}