| 98 | |
| 99 | |
| 100 | void BpfCompressor::finish() |
| 101 | { |
| 102 | // Pop our special stream so that we can write the the file. |
| 103 | delete m_out.popStream(); |
| 104 | |
| 105 | // Deflate and write the result to the output file. |
| 106 | int ret = Z_OK; |
| 107 | while (ret == Z_OK) |
| 108 | { |
| 109 | ret = ::deflate(&m_strm, Z_FINISH); |
| 110 | size_t written = CHUNKSIZE - m_strm.avail_out; |
| 111 | m_compressedSize += written; |
| 112 | m_out.put(m_tmpbuf, written); |
| 113 | m_strm.avail_out = CHUNKSIZE; |
| 114 | m_strm.next_out = m_tmpbuf; |
| 115 | } |
| 116 | if (ret != Z_STREAM_END) |
| 117 | throw error("Couldn't close BPF compression stream."); |
| 118 | deflateEnd(&m_strm); |
| 119 | |
| 120 | // Mark our position so that we can get back here. |
| 121 | OStreamMarker blockEnd(m_out); |
| 122 | |
| 123 | // Rewind to the start of the block and write the size bytes. |
| 124 | m_blockStart.rewind(); |
| 125 | m_out << (uint32_t)m_rawSize << (uint32_t)m_compressedSize; |
| 126 | |
| 127 | // Set the position back to the end of the block. |
| 128 | blockEnd.rewind(); |
| 129 | } |
| 130 | |
| 131 | #else |
| 132 |
no test coverage detected