IsZipFile() public static method

Checks a stream to see if it contains a valid zip archive.

This method reads the zip archive contained in the specified stream, verifying the ZIP metadata as it reads. If testExtract is true, this method also extracts each entry in the archive, dumping all the bits into Stream.Null.

If everything succeeds, then the method returns true. If anything fails - for example if an incorrect signature or CRC is found, indicating a corrupt file, the the method returns false. This method also returns false for a file that does not exist.

If testExtract is true, this method reads in the content for each entry, expands it, and checks CRCs. This provides an additional check beyond verifying the zip header data.

If testExtract is true, and if any of the zip entries are protected with a password, this method will return false. If you want to verify a ZipFile that has entries which are protected with a password, you will need to do that manually.

public static IsZipFile ( Stream stream, bool testExtract ) : bool
stream Stream The stream to check.
testExtract bool true if the caller wants to extract each entry.
return bool
 /// <summary>
 ///  A wrapper for <see cref="ZipFile.IsZipFile(string, bool)">ZipFile.IsZipFile(string, bool)</see>
 /// </summary>
 /// <remarks>
 /// We cannot use "overloaded" Method names in COM interop.
 /// So, here, we use a unique name.
 /// </remarks>
 /// <param name="filename">The filename to of the zip file to check.</param>
 /// <returns>true if the file contains a valid zip file.</returns>
 public bool IsZipFileWithExtract(string filename)
 {
     return(ZipFile.IsZipFile(filename, true));
 }
 /// <summary>
 ///  A wrapper for <see cref="ZipFile.IsZipFile(string)">ZipFile.IsZipFile(string)</see>
 /// </summary>
 /// <param name="filename">The filename to of the zip file to check.</param>
 /// <returns>true if the file contains a valid zip file.</returns>
 public bool IsZipFile(string filename)
 {
     return(ZipFile.IsZipFile(filename));
 }