Skip to content

Commit

Permalink
SporeModManager: use global std::vector<char>() buffer in Zip.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Nov 20, 2023
1 parent 0b27418 commit 2f7463b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions SporeModManager/SporeModManagerHelpers/Zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace SporeModManagerHelpers;
//

static std::map<std::filesystem::path, std::ifstream> l_ZipFileStreams;
static std::vector<char> l_ZipFileBuffer(UNZIP_READ_SIZE);

//
// Local Functions
Expand Down Expand Up @@ -133,7 +134,6 @@ bool Zip::CloseFile(ZipFile zipFile)

bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesystem::path outputFile)
{
static std::vector<char> buffer(UNZIP_READ_SIZE);
int bytesRead = 0;
std::ofstream outputFileStream;

Expand All @@ -159,7 +159,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst

do
{
bytesRead = unzReadCurrentFile(zipFile, buffer.data(), UNZIP_READ_SIZE);
bytesRead = unzReadCurrentFile(zipFile, l_ZipFileBuffer.data(), UNZIP_READ_SIZE);
if (bytesRead < 0)
{
unzCloseCurrentFile(zipFile);
Expand All @@ -168,7 +168,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst
}
else if (bytesRead > 0)
{
outputFileStream.write(buffer.data(), bytesRead);
outputFileStream.write(l_ZipFileBuffer.data(), bytesRead);
}
} while (bytesRead > 0);

Expand All @@ -180,7 +180,6 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst

bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector<char>& outBuffer)
{
static std::vector<char> buffer(UNZIP_READ_SIZE);
int bytesRead = 0;

// try to find file in zip
Expand All @@ -200,7 +199,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector<c

do
{
bytesRead = unzReadCurrentFile(zipFile, buffer.data(), UNZIP_READ_SIZE);
bytesRead = unzReadCurrentFile(zipFile, l_ZipFileBuffer.data(), UNZIP_READ_SIZE);
if (bytesRead < 0)
{
unzCloseCurrentFile(zipFile);
Expand All @@ -209,7 +208,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector<c
}
else if (bytesRead > 0)
{
outBuffer.insert(outBuffer.end(), buffer.begin(), std::next(buffer.begin(), bytesRead));
outBuffer.insert(outBuffer.end(), l_ZipFileBuffer.begin(), l_ZipFileBuffer.begin() + bytesRead);
}
} while (bytesRead > 0);

Expand Down

0 comments on commit 2f7463b

Please sign in to comment.