call lzma_init_encoder before each compression
This commit is contained in:
parent
abbfcd5eb8
commit
0cf1a1c18b
@ -22,17 +22,25 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
const std::filesystem::path directory = argc > 1 ? argv[1] : std::filesystem::current_path();
|
||||
lzma_stream strm = LZMA_STREAM_INIT;
|
||||
bool success = lzma_init_encoder(&strm, COMPRESSION_PRESET);
|
||||
bool success = true;
|
||||
|
||||
if (success)
|
||||
{
|
||||
for (const auto &entry : std::filesystem::directory_iterator(directory))
|
||||
{
|
||||
const std::string path = entry.path().string();
|
||||
if (entry.is_regular_file() && stringutils::has_any_ending(stringutils::to_lower(path), ENDINGS))
|
||||
|
||||
if (!entry.is_regular_file() || !stringutils::has_any_ending(stringutils::to_lower(path), ENDINGS))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "Compressing " + path + "..." << std::flush;
|
||||
|
||||
if (!lzma_init_encoder(&strm, COMPRESSION_PRESET))
|
||||
{
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string output_path = path + ".xz";
|
||||
|
||||
FILE *infile = std::fopen(path.c_str(), "rb");
|
||||
@ -49,17 +57,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
std::cout << " FAILED!" << std::endl
|
||||
<< std::flush;
|
||||
std::cout << " FAILED!" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
std::filesystem::remove(path);
|
||||
|
||||
std::cout << " OK!" << std::endl
|
||||
<< std::flush;
|
||||
}
|
||||
}
|
||||
std::cout << " OK!" << std::endl;
|
||||
}
|
||||
|
||||
lzma_end(&strm);
|
||||
|
Loading…
Reference in New Issue
Block a user