Added ZipReader::IsZip()

This commit is contained in:
Alex Zolotarev 2011-07-22 15:38:07 +03:00 committed by Alex Zolotarev
parent efc5f6aa81
commit aae0710a08
3 changed files with 13 additions and 0 deletions

View file

@ -94,11 +94,13 @@ UNIT_TEST(ZipFilesList)
FileWriter f(ZIPFILE);
f.Write(zipBytes2, ARRAY_SIZE(zipBytes2) - 1);
}
TEST(ZipFileReader::IsZip(ZIPFILE), ());
string const ZIPFILE_INVALID = "invalid_test.zip";
{
FileWriter f(ZIPFILE_INVALID);
f.Write(invalidZip, ARRAY_SIZE(invalidZip) - 1);
}
TEST(!ZipFileReader::IsZip(ZIPFILE_INVALID), ());
try
{

View file

@ -64,3 +64,12 @@ vector<string> ZipFileReader::FilesList(string const & zipContainer)
return filesList;
}
bool ZipFileReader::IsZip(string const & zipContainer)
{
unzFile zip = unzOpen64(zipContainer.c_str());
if (!zip)
return false;
unzClose(zip);
return true;
}

View file

@ -16,4 +16,6 @@ public:
ZipFileReader(string const & container, string const & file);
static vector<string> FilesList(string const & zipContainer);
/// Quick version without exceptions
static bool IsZip(string const & zipContainer);
};