+static uint64_t computeBufferLength(uint64_t const compressedLength) {
+ constexpr uint64_t kMaxBufferLength = uint64_t(4) << 20; // 4 MiB
+ constexpr uint64_t kBlockSize = uint64_t(32) << 10; // 32 KiB
+ const uint64_t goodBufferSize = 4 * std::max(kBlockSize, compressedLength);
+ return std::min(goodBufferSize, kMaxBufferLength);
+}
+