diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-05-30 23:04:48 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-05-30 23:04:48 +0900 |
| commit | 34207cda0101cc98d328b98ea627184dae15c845 (patch) | |
| tree | 62aa86f91810d46782d825a37b1a7d5c934d18e6 /src/GZipEncoder.cc | |
| parent | 70b7394b21611fcb4d143b9a520576db93145671 (diff) | |
Don't throw exception if Z_BUF_ERROR is encountered in GZipEncoder.
Diffstat (limited to 'src/GZipEncoder.cc')
| -rw-r--r-- | src/GZipEncoder.cc | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/src/GZipEncoder.cc b/src/GZipEncoder.cc index c272ce97..bd57c1f1 100644 --- a/src/GZipEncoder.cc +++ b/src/GZipEncoder.cc @@ -46,7 +46,7 @@ namespace { const int OUTBUF_LENGTH = 4096; } // namespace -GZipEncoder::GZipEncoder():strm_(0), finished_(false) {} +GZipEncoder::GZipEncoder():strm_(0) {} GZipEncoder::~GZipEncoder() { @@ -55,7 +55,6 @@ GZipEncoder::~GZipEncoder() void GZipEncoder::init() { - finished_ = false; release(); strm_ = new z_stream(); strm_->zalloc = Z_NULL; @@ -82,29 +81,20 @@ void GZipEncoder::release() std::string GZipEncoder::encode (const unsigned char* in, size_t length, int flush) { - std::string out; - strm_->avail_in = length; strm_->next_in = const_cast<unsigned char*>(in); - + std::string out; unsigned char outbuf[OUTBUF_LENGTH]; while(1) { strm_->avail_out = OUTBUF_LENGTH; strm_->next_out = outbuf; - int ret = ::deflate(strm_, flush); - - if(ret == Z_STREAM_END) { - finished_ = true; - } else if(ret != Z_OK) { + if(ret == Z_STREAM_ERROR) { throw DL_ABORT_EX(fmt("libz::deflate() failed. cause:%s", strm_->msg)); } - size_t produced = OUTBUF_LENGTH-strm_->avail_out; - out.append(&outbuf[0], &outbuf[produced]); - if(strm_->avail_out > 0) { break; } @@ -112,11 +102,6 @@ std::string GZipEncoder::encode return out; } -bool GZipEncoder::finished() -{ - return finished_; -} - std::string GZipEncoder::str() { internalBuf_ += encode(0, 0, Z_FINISH); |
