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

feat: More robust InputStreamWrapper #175

Merged
merged 1 commit into from
Jul 19, 2023
Merged
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
26 changes: 13 additions & 13 deletions src/silo/common/input_stream_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@

namespace {

std::filesystem::path appendXZ(const std::filesystem::path& filename) {
return {filename.string() + ".xz"};
std::filesystem::path withXZending(const std::filesystem::path& filename) {
return {filename.extension() == ".xz" ? filename.string() : filename.string() + ".xz"};
}

std::filesystem::path appendZST(const std::filesystem::path& filename) {
return {filename.string() + ".zst"};
std::filesystem::path withZSTending(const std::filesystem::path& filename) {
return {filename.extension() == ".zst" ? filename.string() : filename.string() + ".zst"};
}

} // namespace

namespace silo {
InputStreamWrapper::InputStreamWrapper(const std::filesystem::path& filename)
: input_stream(std::make_unique<boost::iostreams::filtering_istream>()) {
if (std::filesystem::exists(filename)) {
SPDLOG_INFO("Detected file without specialized ending, processing raw: " + filename.string());
file = std::ifstream(filename, std::ios::binary);
} else if (std::filesystem::exists(appendXZ(filename))) {
SPDLOG_INFO("Detected file-ending .xz for input file " + filename.string());
file = std::ifstream(appendXZ(filename), std::ios::binary);
input_stream->push(boost::iostreams::lzma_decompressor());
} else if (std::filesystem::exists(appendZST(filename))) {
if (std::filesystem::is_regular_file(withZSTending(filename))) {
SPDLOG_INFO("Detected file-ending .zst for input file " + filename.string());
file = std::ifstream(appendZST(filename), std::ios::binary);
file = std::ifstream(withZSTending(filename), std::ios::binary);
input_stream->push(boost::iostreams::zstd_decompressor());
} else if (std::filesystem::is_regular_file(withXZending(filename))) {
SPDLOG_INFO("Detected file-ending .xz for input file " + filename.string());
file = std::ifstream(withXZending(filename), std::ios::binary);
input_stream->push(boost::iostreams::lzma_decompressor());
} else if (std::filesystem::is_regular_file(filename)) {
SPDLOG_INFO("Detected file without specialized ending, processing raw: " + filename.string());
file = std::ifstream(filename, std::ios::binary);
} else {
throw silo::PreprocessingException(
"Cannot find file with name or associated endings (.xz, .zst): " + filename.string()
Expand Down