| 138 | } |
| 139 | |
| 140 | void ZstdDeflatingAppendableWriteBuffer::finishImpl() |
| 141 | { |
| 142 | next(); |
| 143 | |
| 144 | out.nextIfAtEnd(); |
| 145 | |
| 146 | input.src = reinterpret_cast<unsigned char *>(working_buffer.begin()); |
| 147 | input.size = offset(); |
| 148 | input.pos = 0; |
| 149 | |
| 150 | output.dst = reinterpret_cast<unsigned char *>(out.buffer().begin()); |
| 151 | output.size = out.buffer().size(); |
| 152 | output.pos = out.offset(); |
| 153 | |
| 154 | size_t remaining = ZSTD_compressStream2(cctx, &output, &input, ZSTD_e_end); |
| 155 | while (remaining != 0) |
| 156 | { |
| 157 | if (ZSTD_isError(remaining)) |
| 158 | throw Exception(ErrorCodes::ZSTD_ENCODER_FAILED, "Zstd stream encoder end failed: error: '{}' zstd version: {}", ZSTD_getErrorName(remaining), ZSTD_VERSION_STRING); |
| 159 | |
| 160 | remaining = ZSTD_compressStream2(cctx, &output, &input, ZSTD_e_end); |
| 161 | } |
| 162 | out.position() = out.buffer().begin() + output.pos; |
| 163 | } |
| 164 | |
| 165 | void ZstdDeflatingAppendableWriteBuffer::addEmptyBlock() |
| 166 | { |