Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor compressing arrays for VTU output. #14402

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions source/base/data_out_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ namespace

/**
* Do a zlib compression followed by a base64 encoding of the given data. The
* result is then written to the given stream.
* result is then returned as a string object.
*/
template <typename T>
void
write_compressed_block(const std::vector<T> & data,
const DataOutBase::VtkFlags &flags,
std::ostream & output_stream)
std::string
compress_array(const std::vector<T> & data,
const DataOutBase::CompressionLevel compression_level)
{
if (data.size() != 0)
{
Expand All @@ -169,12 +168,11 @@ namespace

std::vector<unsigned char> compressed_data(compressed_data_length);

int err =
compress2(&compressed_data[0],
&compressed_data_length,
reinterpret_cast<const Bytef *>(data.data()),
uncompressed_size,
get_zlib_compression_level(flags.compression_level));
int err = compress2(&compressed_data[0],
&compressed_data_length,
reinterpret_cast<const Bytef *>(data.data()),
uncompressed_size,
get_zlib_compression_level(compression_level));
(void)err;
Assert(err == Z_OK, ExcInternalError());

Expand All @@ -193,11 +191,12 @@ namespace
const auto header_start =
reinterpret_cast<const unsigned char *>(&compression_header[0]);

output_stream << Utilities::encode_base64(
{header_start,
header_start + 4 * sizeof(std::uint32_t)})
<< Utilities::encode_base64(compressed_data);
return (Utilities::encode_base64(
{header_start, header_start + 4 * sizeof(std::uint32_t)}) +
Utilities::encode_base64(compressed_data));
}
else
return {};
}
#endif

Expand Down Expand Up @@ -2099,7 +2098,7 @@ namespace
{
// compress the data we have in memory and write them to the stream.
// then release the data
write_compressed_block(data, flags, stream);
stream << compress_array(data, flags.compression_level);
}
else
#endif
Expand Down