aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Flate.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf/Pl_Flate.cc')
-rw-r--r--libqpdf/Pl_Flate.cc66
1 files changed, 39 insertions, 27 deletions
diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc
index 67e02d2d..c42d3c28 100644
--- a/libqpdf/Pl_Flate.cc
+++ b/libqpdf/Pl_Flate.cc
@@ -6,12 +6,12 @@
#include <qpdf/QUtil.hh>
#include <qpdf/QIntC.hh>
-Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
- action_e action, unsigned int out_bufsize_int) :
- Pipeline(identifier, next),
- out_bufsize(QIntC::to_size(out_bufsize_int)),
+Pl_Flate::Members::Members(size_t out_bufsize,
+ action_e action) :
+ out_bufsize(out_bufsize),
action(action),
- initialized(false)
+ initialized(false),
+ zdata(0)
{
this->outbuf = new unsigned char[out_bufsize];
// Indirect through zdata to reach the z_stream so we don't have
@@ -38,7 +38,7 @@ Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
zstream.avail_out = QIntC::to_uint(out_bufsize);
}
-Pl_Flate::~Pl_Flate()
+Pl_Flate::Members::~Members()
{
delete [] this->outbuf;
this->outbuf = 0;
@@ -60,10 +60,21 @@ Pl_Flate::~Pl_Flate()
this->zdata = 0;
}
+Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
+ action_e action, unsigned int out_bufsize_int) :
+ Pipeline(identifier, next),
+ m(new Members(QIntC::to_size(out_bufsize_int), action))
+{
+}
+
+Pl_Flate::~Pl_Flate()
+{
+}
+
void
Pl_Flate::write(unsigned char* data, size_t len)
{
- if (this->outbuf == 0)
+ if (this->m->outbuf == 0)
{
throw std::logic_error(
this->identifier +
@@ -79,7 +90,7 @@ Pl_Flate::write(unsigned char* data, size_t len)
{
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
handleData(buf, bytes,
- (action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH));
+ (this->m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH));
bytes_left -= bytes;
buf += bytes;
}
@@ -94,11 +105,11 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
"Pl_Flate: zlib doesn't support data"
" blocks larger than int");
}
- z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
+ z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata));
zstream.next_in = data;
zstream.avail_in = QIntC::to_uint(len);
- if (! this->initialized)
+ if (! this->m->initialized)
{
int err = Z_OK;
@@ -109,7 +120,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
- if (this->action == a_deflate)
+ if (this->m->action == a_deflate)
{
err = deflateInit(&zstream, Z_DEFAULT_COMPRESSION);
}
@@ -123,7 +134,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
#endif
checkError("Init", err);
- this->initialized = true;
+ this->m->initialized = true;
}
int err = Z_OK;
@@ -131,7 +142,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
bool done = false;
while (! done)
{
- if (action == a_deflate)
+ if (this->m->action == a_deflate)
{
err = deflate(&zstream, flush);
}
@@ -139,7 +150,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
{
err = inflate(&zstream, flush);
}
- if ((action == a_inflate) && (err != Z_OK) && zstream.msg &&
+ if ((this->m->action == a_inflate) && (err != Z_OK) && zstream.msg &&
(strcmp(zstream.msg, "incorrect data check") == 0))
{
// Other PDF readers ignore this specific error. Combining
@@ -172,12 +183,12 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
done = true;
}
uLong ready =
- QIntC::to_ulong(this->out_bufsize - zstream.avail_out);
+ QIntC::to_ulong(this->m->out_bufsize - zstream.avail_out);
if (ready > 0)
{
- this->getNext()->write(this->outbuf, ready);
- zstream.next_out = this->outbuf;
- zstream.avail_out = QIntC::to_uint(this->out_bufsize);
+ this->getNext()->write(this->m->outbuf, ready);
+ zstream.next_out = this->m->outbuf;
+ zstream.avail_out = QIntC::to_uint(this->m->out_bufsize);
}
}
break;
@@ -194,16 +205,16 @@ Pl_Flate::finish()
{
try
{
- if (this->outbuf)
+ if (this->m->outbuf)
{
- if (this->initialized)
+ if (this->m->initialized)
{
- z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
+ z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata));
unsigned char buf[1];
buf[0] = '\0';
handleData(buf, 0, Z_FINISH);
int err = Z_OK;
- if (action == a_deflate)
+ if (this->m->action == a_deflate)
{
err = deflateEnd(&zstream);
}
@@ -211,12 +222,12 @@ Pl_Flate::finish()
{
err = inflateEnd(&zstream);
}
- this->initialized = false;
+ this->m->initialized = false;
checkError("End", err);
}
- delete [] this->outbuf;
- this->outbuf = 0;
+ delete [] this->m->outbuf;
+ this->m->outbuf = 0;
}
}
catch (std::exception& e)
@@ -230,10 +241,11 @@ Pl_Flate::finish()
void
Pl_Flate::checkError(char const* prefix, int error_code)
{
- z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
+ z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata));
if (error_code != Z_OK)
{
- char const* action_str = (action == a_deflate ? "deflate" : "inflate");
+ char const* action_str =
+ (this->m->action == a_deflate ? "deflate" : "inflate");
std::string msg =
this->identifier + ": " + action_str + ": " + prefix + ": ";