MCPcopy Create free account
hub / github.com/acl-dev/acl / update

Method update

lib_acl_cpp/src/stdlib/zlib_stream.cpp:323–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321#define BUF_MIN 4000
322
323bool zlib_stream::update(int (*func)(z_stream*, int),
324 zlib_flush_t flag, const char* in, int len, string* out)
325{
326 if (func == NULL) {
327 logger_warn("func null, zlib maybe not loaded yet");
328 return false;
329 }
330
331 if (finished_) {
332 return true;
333 }
334
335 if (in == NULL || len < 0 || out == NULL) {
336 logger_warn("invalid args, in=%p, len=%d, out=%p", in, len, out);
337 return false;
338 }
339
340 int pos = 0;
341 int dlen, nbuf, ret;
342
343 zstream_->avail_out = 0;
344
345 while (true) {
346 if (len < 0) {
347 logger_error("when update, invalid len=%d", len);
348 return false;
349 }
350
351 nbuf = (int) (out->capacity() - out->length());
352
353 // ��Ҫ��֤����������Ŀ��ÿռ�
354 if (nbuf < BUF_MIN) {
355 nbuf = (int) out->length() + BUF_MIN;
356 out->space(nbuf);
357 }
358
359 dlen = (int) out->length();
360 nbuf = (int) out->capacity() - dlen;
361 if (nbuf < BUF_MIN) {
362 logger_error("no space available, nbuf: %d < %d",
363 nbuf, BUF_MIN);
364 return false;
365 }
366
367 zstream_->next_in = (unsigned char*) in + pos;
368 zstream_->avail_in = (unsigned int) len;
369 zstream_->next_out = (unsigned char*) out->c_str() + dlen;
370 zstream_->avail_out = (unsigned int) nbuf;
371
372 ret = func(zstream_, flag);
373 if (ret == Z_STREAM_END) {
374 finished_ = true;
375
376 if (flag != Z_FINISH && func != __inflate) {
377 logger_error("flag=%d, func=%p, inflate=%p",
378 flag, func, __inflate);
379 return false;
380 }

Callers

nothing calls this directly

Calls 4

capacityMethod · 0.80
lengthMethod · 0.45
spaceMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected