Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLev Dragunov <l.dragunov@corp.mail.ru>2016-04-22 13:25:12 +0300
committerYuri Gorshenin <y@maps.me>2016-05-10 15:29:44 +0300
commit9375997212876b739a713dd49caf99821be8466d (patch)
tree9eb5513499d1d1eb6c429234b90273fb5016f449 /coding/zip_reader.cpp
parent0d2847d2bbd017aa5d44e0727bf1281e55a93c7d (diff)
Srtm reader with tests.
Diffstat (limited to 'coding/zip_reader.cpp')
-rw-r--r--coding/zip_reader.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp
index 32de85bcbf..4c37d66090 100644
--- a/coding/zip_reader.cpp
+++ b/coding/zip_reader.cpp
@@ -117,3 +117,31 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn
outFileGuard.release();
}
+
+char* ZipFileReader::UnzipFileToMemory(string const & zipContainer, string const & fileInZip)
+{
+ unzFile zip = unzOpen64(zipContainer.c_str());
+ if (!zip)
+ MYTHROW(OpenZipException, ("Can't get zip file handle", zipContainer));
+ MY_SCOPE_GUARD(zipGuard, bind(&unzClose, zip));
+
+ if (UNZ_OK != unzLocateFile(zip, fileInZip.c_str(), 1))
+ MYTHROW(LocateZipException, ("Can't locate file inside zip", fileInZip));
+
+ if (UNZ_OK != unzOpenCurrentFile(zip))
+ MYTHROW(LocateZipException, ("Can't open file inside zip", fileInZip));
+ MY_SCOPE_GUARD(currentFileGuard, bind(&unzCloseCurrentFile, zip));
+
+ unz_file_info64 fileInfo;
+ if (UNZ_OK != unzGetCurrentFileInfo64(zip, &fileInfo, NULL, 0, NULL, 0, NULL, 0))
+ MYTHROW(LocateZipException, ("Can't get uncompressed file size inside zip", fileInZip));
+ size_t const uncompressedFileSize = fileInfo.uncompressed_size;
+
+ char* buf= new char[uncompressedFileSize];
+
+ int const readBytes = unzReadCurrentFile(zip, buf, uncompressedFileSize);
+ if (readBytes < 0)
+ MYTHROW(InvalidZipException, ("Error", readBytes, "while unzipping", fileInZip, "from", zipContainer));
+
+ return buf;
+}