diff --git a/src/IO/LzmaReadBuffer.cpp b/src/IO/LzmaReadBuffer.cpp index 1763a101694..22fda48b3c6 100644 --- a/src/IO/LzmaReadBuffer.cpp +++ b/src/IO/LzmaReadBuffer.cpp @@ -1,10 +1,12 @@ #include -namespace DB { -namespace ErrorCodes { +namespace DB +{ +namespace ErrorCodes +{ extern const int LZMA_STREAM_DECODER_FAILED; } -LzmaReadBuffer::LzmaReadBuffer(std::unique_ptr in_, size_t buf_size, char* existing_memory, size_t alignment) +LzmaReadBuffer::LzmaReadBuffer(std::unique_ptr in_, size_t buf_size, char * existing_memory, size_t alignment) : BufferWithOwnMemory(buf_size, existing_memory, alignment), in(std::move(in_)), eof(false) { lstr = LZMA_STREAM_INIT; @@ -20,9 +22,10 @@ LzmaReadBuffer::LzmaReadBuffer(std::unique_ptr in_, size_t buf_size, lzma_ret ret = lzma_stream_decoder(&lstr, memlimit, LZMA_CONCATENATED); // lzma does not provide api for converting error code to string unlike zlib if (ret != LZMA_OK) - throw Exception(std::string("lzma_stream_decoder initialization failed: error code: ") + std::to_string(ret) + "; lzma version: " - + LZMA_VERSION_STRING, - ErrorCodes::LZMA_STREAM_DECODER_FAILED); + throw Exception( + std::string("lzma_stream_decoder initialization failed: error code: ") + std::to_string(ret) + + "; lzma version: " + LZMA_VERSION_STRING, + ErrorCodes::LZMA_STREAM_DECODER_FAILED); } LzmaReadBuffer::~LzmaReadBuffer() @@ -35,12 +38,13 @@ bool LzmaReadBuffer::nextImpl() if (eof) return false; - if (!lstr.avail_in) { + if (!lstr.avail_in) + { in->nextIfAtEnd(); - lstr.next_in = reinterpret_cast(in->position()); + lstr.next_in = reinterpret_cast(in->position()); lstr.avail_in = in->buffer().end() - in->position(); } - lstr.next_out = reinterpret_cast(internal_buffer.begin()); + lstr.next_out = reinterpret_cast(internal_buffer.begin()); lstr.avail_out = internal_buffer.size(); lzma_ret ret = lzma_code(&lstr, LZMA_RUN); @@ -48,23 +52,29 @@ bool LzmaReadBuffer::nextImpl() in->position() = in->buffer().end() - lstr.avail_in; working_buffer.resize(internal_buffer.size() - lstr.avail_out); - if (ret == LZMA_STREAM_END) { - if (in->eof()) { + if (ret == LZMA_STREAM_END) + { + if (in->eof()) + { eof = true; return working_buffer.size() != 0; - } else { - throw Exception(ErrorCodes::LZMA_STREAM_DECODER_FAILED, - "lzma decoder finished, but stream is still alive: error code: {}; lzma version: {}", - ret, - LZMA_VERSION_STRING); + } + else + { + throw Exception( + ErrorCodes::LZMA_STREAM_DECODER_FAILED, + "lzma decoder finished, but stream is still alive: error code: {}; lzma version: {}", + ret, + LZMA_VERSION_STRING); } } if (ret != LZMA_OK) - throw Exception(ErrorCodes::LZMA_STREAM_DECODER_FAILED, - "lzma_stream_decoder failed: error code: error codeL {}; lzma version: {}", - ret, - LZMA_VERSION_STRING); + throw Exception( + ErrorCodes::LZMA_STREAM_DECODER_FAILED, + "lzma_stream_decoder failed: error code: error codeL {}; lzma version: {}", + ret, + LZMA_VERSION_STRING); return true; }