diff options
author | Alex Zolotarev <alex@maps.me> | 2015-08-18 22:02:44 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 03:01:41 +0300 |
commit | dbe1feb585a88510a03cc140a5269b58fd9e7813 (patch) | |
tree | 8e83a4c4b80a643e1e1eee0740d4489f37e81123 /coding | |
parent | 36e6f0d996f5967a0d3a2f5072b5dadb05aee76c (diff) |
Minor ZipReader improvements.
Diffstat (limited to 'coding')
-rw-r--r-- | coding/zip_creator.cpp | 8 | ||||
-rw-r--r-- | coding/zip_reader.cpp | 7 |
2 files changed, 6 insertions, 9 deletions
diff --git a/coding/zip_creator.cpp b/coding/zip_creator.cpp index 2831100f3c..dca31e1674 100644 --- a/coding/zip_creator.cpp +++ b/coding/zip_creator.cpp @@ -13,7 +13,6 @@ #include "std/vector.hpp" #include "std/ctime.hpp" #include "std/algorithm.hpp" -#include "std/unique_ptr.hpp" #include "3party/minizip/zip.h" @@ -58,8 +57,6 @@ void CreateTMZip(tm_zip & res) bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, string const & zipFilePath) { - unique_ptr<char[]> buffer(new char[ZIP_FILE_BUFFER_SIZE]); - // 2. Open zip file for writing. MY_SCOPE_GUARD(outFileGuard, bind(&my::DeleteFileX, cref(zipFilePath))); ZipHandle zip(zipFilePath); @@ -87,12 +84,13 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str uint64_t const fileSize = file.Size(); uint64_t currSize = 0; + char buffer[ZIP_FILE_BUFFER_SIZE]; while (currSize < fileSize) { unsigned int const toRead = min(ZIP_FILE_BUFFER_SIZE, static_cast<unsigned int>(fileSize - currSize)); - file.Read(currSize, &buffer[0], toRead); + file.Read(currSize, buffer, toRead); - if (ZIP_OK != zipWriteInFileInZip(zip.Handle(), &buffer[0], toRead)) + if (ZIP_OK != zipWriteInFileInZip(zip.Handle(), buffer, toRead)) return false; currSize += toRead; diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp index a2a59b8178..32de85bcbf 100644 --- a/coding/zip_reader.cpp +++ b/coding/zip_reader.cpp @@ -76,8 +76,6 @@ bool ZipFileReader::IsZip(string const & zipContainer) void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileInZip, string const & outFilePath, ProgressFn progressFn) { - unique_ptr<char[]> buf(new char[ZIP_FILE_BUFFER_SIZE]); - unzFile zip = unzOpen64(zipContainer.c_str()); if (!zip) MYTHROW(OpenZipException, ("Can't get zip file handle", zipContainer)); @@ -100,11 +98,12 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn FileWriter outFile(outFilePath); uint64_t pos = 0; + char buf[ZIP_FILE_BUFFER_SIZE]; while (true) { - int const readBytes = unzReadCurrentFile(zip, &buf[0], ZIP_FILE_BUFFER_SIZE); + int const readBytes = unzReadCurrentFile(zip, buf, ZIP_FILE_BUFFER_SIZE); if (readBytes > 0) - outFile.Write(&buf[0], static_cast<size_t>(readBytes)); + outFile.Write(buf, static_cast<size_t>(readBytes)); else if (readBytes < 0) MYTHROW(InvalidZipException, ("Error", readBytes, "while unzipping", fileInZip, "from", zipContainer)); else |