Skip to content

Commit

Permalink
Don't use compression result if it's not least 4 bytes smaller
Browse files Browse the repository at this point in the history
This should better reflect the vanilla behavior
  • Loading branch information
SydMontague committed Jan 31, 2021
1 parent aa07039 commit 78deebc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions DSCSTools/MDB1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,19 @@ CompressionResult getFileData(const boost::filesystem::path path, const bool com
size_t destSize;
char* outputData = new char[comp.getMaxCompressedSize(length)];
doboz::Result res = comp.compress(data, length, outputData, comp.getMaxCompressedSize(length), destSize);
delete data;


if (res != doboz::RESULT_OK)
std::cout << "Error: something went wrong while compressing, doboz error code: " << res << std::endl;

return { (uint32_t) length, (uint32_t) destSize, outputData };
}
else {
return { (uint32_t) length, (uint32_t) length, data };
if (destSize + 4 < length) {
delete data;
return { (uint32_t) length, (uint32_t) destSize, outputData };
}
else
delete outputData;
}

return { (uint32_t) length, (uint32_t) length, data };
}

void packMDB1(const boost::filesystem::path source, const boost::filesystem::path target, const bool compress) {
Expand Down

0 comments on commit 78deebc

Please sign in to comment.