diff options
-rw-r--r-- | src/ZHandle.cc | 9 | ||||
-rw-r--r-- | tests/test-Handles.cc | 30 |
2 files changed, 35 insertions, 4 deletions
diff --git a/src/ZHandle.cc b/src/ZHandle.cc index 4f216c7..aa7bde7 100644 --- a/src/ZHandle.cc +++ b/src/ZHandle.cc @@ -22,14 +22,14 @@ Balau::ZStream::ZStream(const IO<Handle> & h, int level, header_t header) : m_h( } void Balau::ZStream::close() throw (GeneralException) { - if (m_in) { - free(m_in); - m_in = NULL; - } if (m_h->canWrite()) finish(); inflateEnd(&m_zin); deflateEnd(&m_zout); + if (m_in) { + free(m_in); + m_in = NULL; + } if (!m_detached) m_h->close(); m_closed = true; @@ -78,6 +78,7 @@ ssize_t Balau::ZStream::read(void * buf, size_t count) throw (GeneralException) size_t r = m_h->read(m_in, BLOCK_SIZE); if (r <= 0) return readTotal; + m_zin.avail_in = r; } Task::operationYield(); int r = inflate(&m_zin, Z_SYNC_FLUSH); diff --git a/tests/test-Handles.cc b/tests/test-Handles.cc index d2e2396..04c35fc 100644 --- a/tests/test-Handles.cc +++ b/tests/test-Handles.cc @@ -125,5 +125,35 @@ void MainTask::Do() { z->writeString("foobar\n"); } + { + IO<Input> i(new Input("tests/out.z")); + IO<ZStream> z(new ZStream(i)); + IO<BStream> s(new BStream(z)); + z->detach(); + s->detach(); + String f = s->readString(); + TAssert(f == "foobar"); + } + + { + IO<Input> i(new Input("tests/out.gz")); + IO<ZStream> z(new ZStream(i, Z_BEST_COMPRESSION, ZStream::GZIP)); + IO<BStream> s(new BStream(z)); + z->detach(); + s->detach(); + String f = s->readString(); + TAssert(f == "foobar"); + } + + { + IO<Input> i(new Input("tests/out.raw")); + IO<ZStream> z(new ZStream(i, Z_BEST_COMPRESSION, ZStream::RAW)); + IO<BStream> s(new BStream(z)); + z->detach(); + s->detach(); + String f = s->readString(); + TAssert(f == "foobar"); + } + Printer::log(M_STATUS, "Test::Handles passed."); } |