2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/utils/ByteFlow.h"
|
|
|
|
#include "td/utils/Gzip.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
#if TD_HAVE_ZLIB
|
|
|
|
class GzipByteFlow final : public ByteFlowBase {
|
|
|
|
public:
|
|
|
|
GzipByteFlow() = default;
|
|
|
|
|
|
|
|
explicit GzipByteFlow(Gzip::Mode mode) {
|
|
|
|
gzip_.init(mode).ensure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_decode() {
|
|
|
|
gzip_.init_decode().ensure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_encode() {
|
|
|
|
gzip_.init_encode().ensure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_max_output_size(size_t max_output_size) {
|
|
|
|
max_output_size_ = max_output_size;
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
bool loop() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Gzip gzip_;
|
2022-10-12 14:59:58 +02:00
|
|
|
size_t uncommitted_size_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
size_t total_output_size_ = 0;
|
|
|
|
size_t max_output_size_ = std::numeric_limits<size_t>::max();
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace td
|