Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(clp_s): delete clp_s::FileReader #711

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ set(SOURCE_FILES_clp_s_unitTest
src/clp_s/DictionaryEntry.hpp
src/clp_s/DictionaryWriter.cpp
src/clp_s/DictionaryWriter.hpp
src/clp_s/FileReader.cpp
src/clp_s/FileReader.hpp
src/clp_s/FileWriter.cpp
src/clp_s/FileWriter.hpp
src/clp_s/InputConfig.cpp
Expand Down
12 changes: 5 additions & 7 deletions components/core/src/clp_s/ArchiveWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,21 @@ void ArchiveWriter::write_archive_files(
FileWriter& archive_writer,
std::vector<ArchiveFileInfo> const& files
) {
FileReader reader;
for (auto const& file : files) {
std::string file_path = m_archive_path + file.n;
reader.open(file_path);
clp::FileReader reader(file_path);
char read_buffer[cReadBlockSize];
while (true) {
size_t num_bytes_read{0};
ErrorCode const error_code
clp::ErrorCode const error_code
= reader.try_read(read_buffer, cReadBlockSize, num_bytes_read);
if (ErrorCodeEndOfFile == error_code) {
if (clp::ErrorCode::ErrorCode_EndOfFile == error_code) {
break;
} else if (ErrorCodeSuccess != error_code) {
throw OperationFailed(error_code, __FILENAME__, __LINE__);
} else if (clp::ErrorCode::ErrorCode_Success != error_code) {
throw OperationFailed(static_cast<ErrorCode>(error_code), __FILENAME__, __LINE__);
}
archive_writer.write(read_buffer, num_bytes_read);
}
reader.close();
if (false == std::filesystem::remove(file_path)) {
throw OperationFailed(ErrorCodeFileExists, __FILENAME__, __LINE__);
}
Expand Down
2 changes: 0 additions & 2 deletions components/core/src/clp_s/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ set(
DictionaryWriter.cpp
DictionaryWriter.hpp
ErrorCode.hpp
FileReader.cpp
FileReader.hpp
FileWriter.cpp
FileWriter.hpp
InputConfig.cpp
Expand Down
48 changes: 23 additions & 25 deletions components/core/src/clp_s/CommandLineArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <spdlog/spdlog.h>

#include "../clp/cli_utils.hpp"
#include "../clp/FileReader.hpp"
#include "../clp/type_utils.hpp"
#include "../reducer/types.hpp"
#include "FileReader.hpp"

namespace po = boost::program_options;

Expand All @@ -33,34 +33,32 @@ bool read_paths_from_file(
std::string const& input_path_list_file_path,
std::vector<std::string>& path_destination
) {
FileReader reader;
auto error_code = reader.try_open(input_path_list_file_path);
if (ErrorCodeFileNotFound == error_code) {
SPDLOG_ERROR(
"Failed to open input path list file {} - file not found",
input_path_list_file_path
);
return false;
} else if (ErrorCodeSuccess != error_code) {
SPDLOG_ERROR("Error opening input path list file {}", input_path_list_file_path);
return false;
}

std::string line;
while (true) {
error_code = reader.try_read_to_delimiter('\n', false, false, line);
if (ErrorCodeSuccess != error_code) {
break;
}
if (false == line.empty()) {
path_destination.push_back(line);
try {
clp::FileReader reader(input_path_list_file_path);
std::string line;
clp::ErrorCode error_code;
while (true) {
error_code = reader.try_read_to_delimiter('\n', false, false, line);
if (clp::ErrorCode::ErrorCode_Success != error_code) {
break;
}
if (false == line.empty()) {
path_destination.push_back(line);
}
}
}

if (ErrorCodeEndOfFile != error_code) {
if (clp::ErrorCode::ErrorCode_EndOfFile != error_code) {
return false;
}
return true;
} catch (clp::FileReader::OperationFailed const& e) {
SPDLOG_ERROR(
"Failed to open file for reading - {} - {}",
input_path_list_file_path,
e.what()
);
return false;
}
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions components/core/src/clp_s/Decompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include <string>

#include "../clp/FileReader.hpp"
#include "../clp/ReaderInterface.hpp"
#include "FileReader.hpp"
#include "TraceableException.hpp"

namespace clp_s {
Expand Down Expand Up @@ -49,7 +49,7 @@ class Decompressor {
* @param file_reader
* @param file_read_buffer_capacity The maximum amount of data to read from a file at a time
*/
virtual void open(FileReader& file_reader, size_t file_read_buffer_capacity) = 0;
virtual void open(clp::FileReader& file_reader, size_t file_read_buffer_capacity) = 0;

/**
* Initializes the decompressor to decompress from an open clp reader
Expand Down
150 changes: 0 additions & 150 deletions components/core/src/clp_s/FileReader.cpp

This file was deleted.

Loading