From c436f214669b5895f64cf429be383cf48f3e0f6a Mon Sep 17 00:00:00 2001 From: Bingran Hu Date: Fri, 6 Dec 2024 00:44:25 -0500 Subject: [PATCH] Apply suggestions from code review Co-authored-by: haiqi96 <14502009+haiqi96@users.noreply.github.com> --- .../core/src/clp/streaming_compression/lzma/Compressor.cpp | 5 ++++- .../core/src/clp/streaming_compression/lzma/Compressor.hpp | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/core/src/clp/streaming_compression/lzma/Compressor.cpp b/components/core/src/clp/streaming_compression/lzma/Compressor.cpp index 65445061a..8d518249c 100644 --- a/components/core/src/clp/streaming_compression/lzma/Compressor.cpp +++ b/components/core/src/clp/streaming_compression/lzma/Compressor.cpp @@ -156,6 +156,9 @@ auto Compressor::write(char const* data, size_t data_length) -> void { } auto Compressor::flush() -> void { + if (nullptr == m_compressed_stream_file_writer) { + throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__); + } flush_lzma(LZMA_SYNC_FLUSH); } @@ -228,7 +231,7 @@ auto Compressor::flush_lzma(lzma_action flush_action) -> void { case LZMA_BUF_ERROR: // No encoding progress can be made // NOTE: this can happen if we are using LZMA_FULL_FLUSH or // LZMA_FULL_BARRIER. These two actions keeps encoding input - // data alongside flushing already encoded but buffered data. + // data alongside flushing buffered encoded data. SPDLOG_ERROR("LZMA compressor input stream is corrupt."); throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__); default: diff --git a/components/core/src/clp/streaming_compression/lzma/Compressor.hpp b/components/core/src/clp/streaming_compression/lzma/Compressor.hpp index c8c12b9cb..323464545 100644 --- a/components/core/src/clp/streaming_compression/lzma/Compressor.hpp +++ b/components/core/src/clp/streaming_compression/lzma/Compressor.hpp @@ -94,7 +94,7 @@ class Compressor : public ::clp::streaming_compression::Compressor { * Invoke lzma_code() repeatedly with LZMA_RUN until the input is exhausted * * At the end of the workflow, the last bytes of encoded data may still be - * buffered and thus not immediately available at the output block buffer. + * buffered in the LZMA stream and thus not immediately available at the output block buffer. * * Assumes input stream and output block buffer are both in valid states. * @throw `OperationFailed` if LZMA returns an unexpected error value @@ -113,8 +113,8 @@ class Compressor : public ::clp::streaming_compression::Compressor { auto flush_lzma(lzma_action flush_action) -> void; /** - * Flushes the current compressed data in the LZMA output buffer to the - * output file handler. Reset the compression buffer to receive new data. + * Flushes the current compressed data in the output block buffer to the + * output file handler. Reset the output block buffer to receive new data. */ auto flush_stream_output_block_buffer() -> void;