aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/ZlibInStream.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/rdr/ZlibInStream.cxx')
-rw-r--r--common/rdr/ZlibInStream.cxx55
1 files changed, 8 insertions, 47 deletions
diff --git a/common/rdr/ZlibInStream.cxx b/common/rdr/ZlibInStream.cxx
index 839cf0d0..675600d5 100644
--- a/common/rdr/ZlibInStream.cxx
+++ b/common/rdr/ZlibInStream.cxx
@@ -24,41 +24,31 @@
using namespace rdr;
-enum { DEFAULT_BUF_SIZE = 16384 };
-
ZlibInStream::ZlibInStream(size_t bufSize_)
- : underlying(0), bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0),
- zs(NULL), bytesIn(0)
+ : BufferedInStream(bufSize_),
+ underlying(0), zs(NULL), bytesIn(0)
{
- ptr = end = start = new U8[bufSize];
init();
}
ZlibInStream::~ZlibInStream()
{
deinit();
- delete [] start;
}
void ZlibInStream::setUnderlying(InStream* is, size_t bytesIn_)
{
underlying = is;
bytesIn = bytesIn_;
- ptr = end = start;
-}
-
-size_t ZlibInStream::pos()
-{
- return offset + ptr - start;
+ skip(avail());
}
void ZlibInStream::flushUnderlying()
{
- ptr = end = start;
-
while (bytesIn > 0) {
- decompress(true);
- end = start; // throw away any data
+ if (!check(1))
+ throw Exception("ZlibInStream: failed to flush remaining stream data");
+ skip(avail());
}
setUnderlying(NULL, 0);
@@ -96,42 +86,13 @@ void ZlibInStream::deinit()
zs = NULL;
}
-size_t ZlibInStream::overrun(size_t itemSize, size_t nItems, bool wait)
-{
- if (itemSize > bufSize)
- throw Exception("ZlibInStream overrun: max itemSize exceeded");
-
- if (end - ptr != 0)
- memmove(start, ptr, end - ptr);
-
- offset += ptr - start;
- end -= ptr - start;
- ptr = start;
-
- while (avail() < itemSize) {
- if (!decompress(wait))
- return 0;
- }
-
- size_t nAvail;
- nAvail = avail() / itemSize;
- if (nAvail < nItems)
- return nAvail;
-
- return nItems;
-}
-
-// decompress() calls the decompressor once. Note that this won't necessarily
-// generate any output data - it may just consume some input data. Returns
-// false if wait is false and we would block on the underlying stream.
-
-bool ZlibInStream::decompress(bool wait)
+bool ZlibInStream::fillBuffer(size_t maxSize, bool wait)
{
if (!underlying)
throw Exception("ZlibInStream overrun: no underlying stream");
zs->next_out = (U8*)end;
- zs->avail_out = start + bufSize - end;
+ zs->avail_out = maxSize;
size_t n = underlying->check(1, 1, wait);
if (n == 0) return false;