summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-05-30 23:04:48 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-05-30 23:04:48 +0900
commit34207cda0101cc98d328b98ea627184dae15c845 (patch)
tree62aa86f91810d46782d825a37b1a7d5c934d18e6 /src
parent70b7394b21611fcb4d143b9a520576db93145671 (diff)
Don't throw exception if Z_BUF_ERROR is encountered in GZipEncoder.
Diffstat (limited to 'src')
-rw-r--r--src/GZipEncoder.cc21
-rw-r--r--src/GZipEncoder.h3
2 files changed, 3 insertions, 21 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);
diff --git a/src/GZipEncoder.h b/src/GZipEncoder.h
index 8f7f3057..850bb5a8 100644
--- a/src/GZipEncoder.h
+++ b/src/GZipEncoder.h
@@ -87,9 +87,6 @@ public:
return encode(in, length, Z_NO_FLUSH);
}
- // Returns true if deflator finished.
- bool finished();
-
// Releases allocated resources.
void release();