16 #ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_COMPRESSION_GZIP_ZLIB_H_
17 #define TENSORFLOW_SERVING_UTIL_NET_HTTP_COMPRESSION_GZIP_ZLIB_H_
23 namespace tensorflow {
34 state_ = IN_HEADER_ID1;
50 Status ReadMore(
const char *inbuf,
int inbuf_len,
const char **header_end);
68 IN_HEADER_MTIME_BYTE_0,
69 IN_HEADER_MTIME_BYTE_1,
70 IN_HEADER_MTIME_BYTE_2,
71 IN_HEADER_MTIME_BYTE_3,
91 uint16_t extra_length_;
100 static constexpr int64_t kMaxUncompressedBytes = 100 * 1024 * 1024;
119 void SetDontHideStreamEnd();
122 void SetCompressionLevel(
int level) { settings_.compression_level_ = level; }
126 void SetCompressionWindowSizeInBits(
int bits) {
127 settings_.window_bits_ = bits;
132 void SetCompressionMemLevel(
int level) { settings_.mem_level_ = level; }
138 static uLong MinCompressbufSize(uLong uncompress_size) {
139 return uncompress_size + uncompress_size / 1000 + 40;
143 int MinFooterSize()
const;
162 int Compress(Bytef *dest, uLongf *destLen,
const Bytef *source,
173 int Uncompress(Bytef *dest, uLongf *destLen,
const Bytef *source,
178 uLongf GzipUncompressedLength(
const Bytef *source, uLong len);
192 int UncompressGzipAndAllocate(Bytef **dest, uLongf *destLen,
193 const Bytef *source, uLong sourceLen);
209 int CompressAtMost(Bytef *dest, uLongf *destLen,
const Bytef *source,
215 int CompressChunkDone(Bytef *dest, uLongf *destLen);
225 int UncompressAtMost(Bytef *dest, uLongf *destLen,
const Bytef *source,
232 bool UncompressChunkDone();
237 bool first_chunk()
const {
return first_chunk_; }
241 static bool HasGzipHeader(
const char *source,
int sourceLen);
245 bool IsGzipFooterComplete()
const;
250 bool IsGzipFooterValid()
const;
253 uLong uncompressed_size()
const {
return uncompressed_size_; }
260 int CompressInit(Bytef *dest, uLongf *destLen,
const Bytef *source,
262 int UncompressInit(Bytef *dest, uLongf *destLen,
const Bytef *source,
267 void UncompressErrorInit();
269 int WriteGzipHeader();
270 int WriteGzipFooter(Bytef *dest, uLongf destLen);
273 int CompressChunkOrAll(Bytef *dest, uLongf *destLen,
const Bytef *source,
274 uLong sourceLen,
int flush_mode);
275 int CompressAtMostOrAll(Bytef *dest, uLongf *destLen,
const Bytef *source,
276 uLong *sourceLen,
int flush_mode);
279 int UncompressChunkOrAll(Bytef *dest, uLongf *destLen,
const Bytef *source,
280 uLong sourceLen,
int flush_mode);
282 int UncompressAtMostOrAll(Bytef *dest, uLongf *destLen,
const Bytef *source,
283 uLong *sourceLen,
int flush_mode);
288 void CompressErrorInit();
292 int compression_level_;
302 bool dont_hide_zstream_end_;
314 Settings init_settings_;
316 z_stream comp_stream_;
318 z_stream uncomp_stream_;
323 uLong uncompressed_size_;
327 Byte gzip_footer_[8];
328 int gzip_footer_bytes_;