diff options
author | Alex Zolotarev <alex@mapswithme.com> | 2013-06-18 11:36:57 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:56:44 +0300 |
commit | a16d85a35f4bbda5b821d2aa049fb441ac30b195 (patch) | |
tree | 78908f852f2c1fee4df470a00a0c0fdf15407f97 /coding | |
parent | 8dabfc9d1b5afb3b414451942045a5fda7694a72 (diff) |
Minor Zip fixes
Diffstat (limited to 'coding')
-rw-r--r-- | coding/zip_creator.cpp | 21 | ||||
-rw-r--r-- | coding/zip_reader.cpp | 2 | ||||
-rw-r--r-- | coding/zip_reader.hpp | 2 |
3 files changed, 15 insertions, 10 deletions
diff --git a/coding/zip_creator.cpp b/coding/zip_creator.cpp index a9a8928906..be37a15b55 100644 --- a/coding/zip_creator.cpp +++ b/coding/zip_creator.cpp @@ -14,18 +14,23 @@ namespace { -struct ZipHandle +class ZipHandle { - zipFile m_zipFile; + zipFile m_zipFileHandle; + +public: ZipHandle(string const & filePath) { - m_zipFile = zipOpen(filePath.c_str(), 0); + m_zipFileHandle = zipOpen(filePath.c_str(), 0); } + ~ZipHandle() { - if (m_zipFile) - zipClose(m_zipFile, NULL); + if (m_zipFileHandle) + zipClose(m_zipFileHandle, NULL); } + + zipFile Handle() const { return m_zipFileHandle; } }; void CreateTMZip(tm_zip & res) @@ -47,7 +52,7 @@ void CreateTMZip(tm_zip & res) bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, string const & zipFilePath) { ZipHandle zip(zipFilePath); - if (!zip.m_zipFile) + if (!zip.Handle()) return false; // Special syntax to initialize struct with zeroes @@ -55,7 +60,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str CreateTMZip(zipInfo.tmz_date); string fileName = filePath; my::GetNameFromFullPath(fileName); - if (zipOpenNewFileInZip(zip.m_zipFile, fileName.c_str(), &zipInfo, + if (::zipOpenNewFileInZip(zip.Handle(), fileName.c_str(), &zipInfo, NULL, 0, NULL, 0, "ZIP from MapsWithMe", Z_DEFLATED, Z_DEFAULT_COMPRESSION) < 0) { return false; @@ -73,7 +78,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str size_t const toRead = min(bufSize, fileSize - currSize); f.Read(currSize, &buffer[0], toRead); - if (ZIP_OK != zipWriteInFileInZip(zip.m_zipFile, &buffer[0], toRead)) + if (ZIP_OK != ::zipWriteInFileInZip(zip.Handle(), &buffer[0], toRead)) return false; currSize += toRead; diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp index 7bafa65595..ba4aa05db7 100644 --- a/coding/zip_reader.cpp +++ b/coding/zip_reader.cpp @@ -98,7 +98,7 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn MY_SCOPE_GUARD(outFileGuard, bind(&FileWriter::DeleteFileX, cref(outFilePath))); FileWriter outFile(outFilePath); - int pos = 0; + uint64_t pos = 0; while (true) { int const readBytes = unzReadCurrentFile(zip, &buf[0], BUF_SIZE); diff --git a/coding/zip_reader.hpp b/coding/zip_reader.hpp index a9070cee39..e85e03ee3f 100644 --- a/coding/zip_reader.hpp +++ b/coding/zip_reader.hpp @@ -13,7 +13,7 @@ private: uint64_t m_uncompressedFileSize; public: - typedef function<void(int, int)> ProgressFn; + typedef function<void(uint64_t, uint64_t)> ProgressFn; /// Contains file name inside zip and it's uncompressed size typedef vector<pair<string, uint32_t> > FileListT; |