Skip to content

Commit

Permalink
Final round
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-hbrhbr committed Nov 22, 2024
1 parent 74d62bf commit 51001db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 10 additions & 5 deletions components/core/src/clp/streaming_compression/zstd/Compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#include "../../TraceableException.hpp"

namespace clp::streaming_compression::zstd {
Compressor::Compressor() {
Compressor::Compressor()
: m_compressed_stream_block{
.dst = m_compressed_stream_block_buffer.data(),
.size = m_compressed_stream_block_buffer.size(),
.pos = 0
} {
if (nullptr == m_compression_stream) {
SPDLOG_ERROR("streaming_compression::zstd::Compressor: ZSTD_createCStream() error");
throw OperationFailed(ErrorCode_Failure, __FILENAME__, __LINE__);
Expand All @@ -28,7 +33,7 @@ auto Compressor::open(FileWriter& file_writer, int compression_level) -> void {

// Setup compression stream
auto const init_result{ZSTD_initCStream(m_compression_stream, compression_level)};
if (ZSTD_error_no_error != ZSTD_getErrorCode(init_result)) {
if (0 != ZSTD_isError(init_result)) {
SPDLOG_ERROR(
"streaming_compression::zstd::Compressor: ZSTD_initCStream() error: {}",
ZSTD_getErrorName(init_result)
Expand Down Expand Up @@ -71,7 +76,7 @@ auto Compressor::write(char const* data, size_t data_length) -> void {
&m_compressed_stream_block,
&uncompressed_stream_block
)};
if (ZSTD_error_no_error != ZSTD_getErrorCode(compress_result)) {
if (0 != ZSTD_isError(compress_result)) {
SPDLOG_ERROR(
"streaming_compression::zstd::Compressor: ZSTD_compressStream() error: {}",
ZSTD_getErrorName(compress_result)
Expand Down Expand Up @@ -99,7 +104,7 @@ auto Compressor::flush() -> void {

m_compressed_stream_block.pos = 0;
auto const end_stream_result{ZSTD_endStream(m_compression_stream, &m_compressed_stream_block)};
if (ZSTD_error_no_error != ZSTD_getErrorCode(end_stream_result)) {
if (0 != ZSTD_isError(end_stream_result)) {
// Note: Output buffer is large enough that it is guaranteed to have enough room to be
// able to flush the entire buffer, so this can only be an error
SPDLOG_ERROR(
Expand Down Expand Up @@ -133,7 +138,7 @@ auto Compressor::flush_without_ending_frame() -> void {
while (true) {
m_compressed_stream_block.pos = 0;
auto const flush_result{ZSTD_flushStream(m_compression_stream, &m_compressed_stream_block)};
if (ZSTD_error_no_error != ZSTD_getErrorCode(flush_result)) {
if (0 != ZSTD_isError(flush_result)) {
SPDLOG_ERROR(
"streaming_compression::zstd::Compressor: ZSTD_flushStream() error: {}",
ZSTD_getErrorName(flush_result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ class Compressor : public ::clp::streaming_compression::Compressor {
bool m_compression_stream_contains_data{false};

Array<char> m_compressed_stream_block_buffer{ZSTD_CStreamOutSize()};
ZSTD_outBuffer m_compressed_stream_block{
.dst = m_compressed_stream_block_buffer.data(),
.size = m_compressed_stream_block_buffer.size(),
.pos = 0
};
ZSTD_outBuffer m_compressed_stream_block;

size_t m_uncompressed_stream_pos{0};
};
Expand Down

0 comments on commit 51001db

Please sign in to comment.