mirror of https://github.com/aria2/aria2
Don't throw exception if Z_BUF_ERROR is encountered in GZipEncoder.
parent
70b7394b21
commit
34207cda01
|
@ -46,7 +46,7 @@ namespace {
|
||||||
const int OUTBUF_LENGTH = 4096;
|
const int OUTBUF_LENGTH = 4096;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
GZipEncoder::GZipEncoder():strm_(0), finished_(false) {}
|
GZipEncoder::GZipEncoder():strm_(0) {}
|
||||||
|
|
||||||
GZipEncoder::~GZipEncoder()
|
GZipEncoder::~GZipEncoder()
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,6 @@ GZipEncoder::~GZipEncoder()
|
||||||
|
|
||||||
void GZipEncoder::init()
|
void GZipEncoder::init()
|
||||||
{
|
{
|
||||||
finished_ = false;
|
|
||||||
release();
|
release();
|
||||||
strm_ = new z_stream();
|
strm_ = new z_stream();
|
||||||
strm_->zalloc = Z_NULL;
|
strm_->zalloc = Z_NULL;
|
||||||
|
@ -82,29 +81,20 @@ void GZipEncoder::release()
|
||||||
std::string GZipEncoder::encode
|
std::string GZipEncoder::encode
|
||||||
(const unsigned char* in, size_t length, int flush)
|
(const unsigned char* in, size_t length, int flush)
|
||||||
{
|
{
|
||||||
std::string out;
|
|
||||||
|
|
||||||
strm_->avail_in = length;
|
strm_->avail_in = length;
|
||||||
strm_->next_in = const_cast<unsigned char*>(in);
|
strm_->next_in = const_cast<unsigned char*>(in);
|
||||||
|
std::string out;
|
||||||
unsigned char outbuf[OUTBUF_LENGTH];
|
unsigned char outbuf[OUTBUF_LENGTH];
|
||||||
while(1) {
|
while(1) {
|
||||||
strm_->avail_out = OUTBUF_LENGTH;
|
strm_->avail_out = OUTBUF_LENGTH;
|
||||||
strm_->next_out = outbuf;
|
strm_->next_out = outbuf;
|
||||||
|
|
||||||
int ret = ::deflate(strm_, flush);
|
int ret = ::deflate(strm_, flush);
|
||||||
|
if(ret == Z_STREAM_ERROR) {
|
||||||
if(ret == Z_STREAM_END) {
|
|
||||||
finished_ = true;
|
|
||||||
} else if(ret != Z_OK) {
|
|
||||||
throw DL_ABORT_EX(fmt("libz::deflate() failed. cause:%s",
|
throw DL_ABORT_EX(fmt("libz::deflate() failed. cause:%s",
|
||||||
strm_->msg));
|
strm_->msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t produced = OUTBUF_LENGTH-strm_->avail_out;
|
size_t produced = OUTBUF_LENGTH-strm_->avail_out;
|
||||||
|
|
||||||
out.append(&outbuf[0], &outbuf[produced]);
|
out.append(&outbuf[0], &outbuf[produced]);
|
||||||
|
|
||||||
if(strm_->avail_out > 0) {
|
if(strm_->avail_out > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -112,11 +102,6 @@ std::string GZipEncoder::encode
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GZipEncoder::finished()
|
|
||||||
{
|
|
||||||
return finished_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GZipEncoder::str()
|
std::string GZipEncoder::str()
|
||||||
{
|
{
|
||||||
internalBuf_ += encode(0, 0, Z_FINISH);
|
internalBuf_ += encode(0, 0, Z_FINISH);
|
||||||
|
|
|
@ -87,9 +87,6 @@ public:
|
||||||
return encode(in, length, Z_NO_FLUSH);
|
return encode(in, length, Z_NO_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if deflator finished.
|
|
||||||
bool finished();
|
|
||||||
|
|
||||||
// Releases allocated resources.
|
// Releases allocated resources.
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue