From a16d85a35f4bbda5b821d2aa049fb441ac30b195 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Tue, 18 Jun 2013 10:36:57 +0300 Subject: [PATCH] Minor Zip fixes --- coding/zip_creator.cpp | 21 +++++++++++++-------- coding/zip_reader.cpp | 2 +- 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 ProgressFn; + typedef function ProgressFn; /// Contains file name inside zip and it's uncompressed size typedef vector > FileListT;