From: Wolfgang Bangerth Date: Tue, 8 Nov 2022 17:26:14 +0000 (-0700) Subject: Refactor compressing arrays for VTU output. X-Git-Tag: v9.5.0-rc1~869^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dadc39e9d9c7d5e8350995af8fca8d0fad17fd6;p=dealii.git Refactor compressing arrays for VTU output. --- diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index aceb6710ff..c520da53c4 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -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 - void - write_compressed_block(const std::vector & data, - const DataOutBase::VtkFlags &flags, - std::ostream & output_stream) + std::string + compress_array(const std::vector & data, + const DataOutBase::CompressionLevel compression_level) { if (data.size() != 0) { @@ -169,12 +168,11 @@ namespace std::vector compressed_data(compressed_data_length); - int err = - compress2(&compressed_data[0], - &compressed_data_length, - reinterpret_cast(data.data()), - uncompressed_size, - get_zlib_compression_level(flags.compression_level)); + int err = compress2(&compressed_data[0], + &compressed_data_length, + reinterpret_cast(data.data()), + uncompressed_size, + get_zlib_compression_level(compression_level)); (void)err; Assert(err == Z_OK, ExcInternalError()); @@ -193,11 +191,12 @@ namespace const auto header_start = reinterpret_cast(&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 @@ -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