| 174 | } |
| 175 | |
| 176 | bool ZstdDeflatingAppendableWriteBuffer::isNeedToAddEmptyBlock() |
| 177 | { |
| 178 | ReadBufferFromFile reader(out.getFileName()); |
| 179 | auto fsize = reader.getFileSize(); |
| 180 | if (fsize > 3) |
| 181 | { |
| 182 | std::array<char, 3> result; |
| 183 | reader.seek(fsize - 3, SEEK_SET); |
| 184 | reader.readStrict(result.data(), 3); |
| 185 | |
| 186 | /// If we don't have correct block in the end, then we need to add it manually. |
| 187 | /// NOTE: maybe we can have the same bytes in case of data corruption/unfinished write. |
| 188 | /// But in this case file still corrupted and we have to remove it. |
| 189 | return result != ZSTD_CORRECT_TERMINATION_LAST_BLOCK; |
| 190 | } |
| 191 | else if (fsize > 0) |
| 192 | { |
| 193 | throw Exception( |
| 194 | ErrorCodes::ZSTD_ENCODER_FAILED, |
| 195 | "Trying to write to non-empty file '{}' with tiny size {}. It can lead to data corruption", |
| 196 | out.getFileName(), fsize); |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | } |
nothing calls this directly
no test coverage detected