| 186 | |
| 187 | |
| 188 | bool ZstdDeflatingAppendableWriteBuffer::isNeedToAddEmptyBlock() |
| 189 | { |
| 190 | auto reader = read_buffer_creator(); |
| 191 | auto fsize = reader->getFileSize(); |
| 192 | if (fsize > 3) |
| 193 | { |
| 194 | std::array<char, 3> result{}; |
| 195 | reader->seek(fsize - 3, SEEK_SET); |
| 196 | reader->readStrict(result.data(), 3); |
| 197 | |
| 198 | /// If we don't have correct block in the end, then we need to add it manually. |
| 199 | /// NOTE: maybe we can have the same bytes in case of data corruption/unfinished write. |
| 200 | /// But in this case file still corrupted and we have to remove it. |
| 201 | return result != ZSTD_CORRECT_TERMINATION_LAST_BLOCK; |
| 202 | } |
| 203 | if (fsize > 0) |
| 204 | { |
| 205 | throw Exception( |
| 206 | ErrorCodes::ZSTD_ENCODER_FAILED, |
| 207 | "Trying to write to non-empty file '{}' with tiny size {}. It can lead to data corruption", |
| 208 | out->getFileName(), |
| 209 | fsize); |
| 210 | } |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | void ZstdDeflatingAppendableWriteBuffer::cancelImpl() noexcept |
| 215 | { |
nothing calls this directly
no test coverage detected