diff options
-rw-r--r-- | coding/coding_tests/zip_reader_test.cpp | 2 | ||||
-rw-r--r-- | coding/zip_reader.cpp | 9 | ||||
-rw-r--r-- | coding/zip_reader.hpp | 2 |
3 files changed, 13 insertions, 0 deletions
diff --git a/coding/coding_tests/zip_reader_test.cpp b/coding/coding_tests/zip_reader_test.cpp index a7d905004a..43b76a018f 100644 --- a/coding/coding_tests/zip_reader_test.cpp +++ b/coding/coding_tests/zip_reader_test.cpp @@ -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 { diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp index ee798f6769..5d85947341 100644 --- a/coding/zip_reader.cpp +++ b/coding/zip_reader.cpp @@ -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; +} diff --git a/coding/zip_reader.hpp b/coding/zip_reader.hpp index beaba2ccdf..7128b587dd 100644 --- a/coding/zip_reader.hpp +++ b/coding/zip_reader.hpp @@ -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); }; |