| 66 | |
| 67 | |
| 68 | void BpfCompressor::compress() |
| 69 | { |
| 70 | // Note our position so that we know how much we've written. |
| 71 | uint32_t rawWritten = (uint32_t)m_out.position(); |
| 72 | |
| 73 | // Pop our temp stream so that we can write the real output file. |
| 74 | delete m_out.popStream(); |
| 75 | |
| 76 | m_rawSize += rawWritten; |
| 77 | |
| 78 | // Deflate the data in the buffer and write it to the output stream. |
| 79 | m_strm.avail_in = rawWritten; |
| 80 | m_strm.next_in = (unsigned char *)m_inbuf.data(); |
| 81 | m_strm.avail_out = CHUNKSIZE; |
| 82 | m_strm.next_out = m_tmpbuf; |
| 83 | while (m_strm.avail_in) |
| 84 | { |
| 85 | int ret = ::deflate(&m_strm, Z_NO_FLUSH); |
| 86 | size_t written = CHUNKSIZE - m_strm.avail_out; |
| 87 | m_compressedSize += written; |
| 88 | m_out.put(m_tmpbuf, written); |
| 89 | m_strm.avail_out = CHUNKSIZE; |
| 90 | m_strm.next_out = m_tmpbuf; |
| 91 | } |
| 92 | |
| 93 | // All data has been written. Reinitialize input buffer's streambuf and |
| 94 | // push it. |
| 95 | m_charbuf.initialize(m_inbuf.data(), m_inbuf.size()); |
| 96 | m_out.pushStream(new std::ostream(&m_charbuf)); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | void BpfCompressor::finish() |