Skip to content
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
7 changes: 5 additions & 2 deletions ssh/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ namespace ssh {
void node::scp_send_file(const std::filesystem::path &from, const std::filesystem::path &to) {
std::ifstream input(from, std::ifstream::binary);
if (input.is_open()) {
std::string data = dynamic_cast<std::ostringstream &>(std::ostringstream{} << input.rdbuf()).str();
std::ostringstream buffer;
buffer << input.rdbuf();
std::string data = buffer.str();
input.close();
scp_write_file(to, data);
} else {
throw std::runtime_error("Cannot find a file");
}
};
}


void node::scp_download_file(const std::filesystem::path &from, const std::filesystem::path &to) {
std::string input = scp_read_file(from);
Expand Down
27 changes: 17 additions & 10 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,24 @@ namespace map_reduce {
throw std::runtime_error("fail during writing to socket");
}


std::pair<std::unique_ptr<KeyValueType>, std::unique_ptr<KeyValueType>>
get_key_value_from_json(const std::string &data, std::unique_ptr<KeyValueTypeFactory> &key_factory,
std::unique_ptr<KeyValueTypeFactory> &value_factory) {
boost::property_tree::ptree pt{};
boost::property_tree::json_parser::read_json(dynamic_cast<std::stringstream &>(std::stringstream{} << data),
pt);
if (pt.get(data_end_flag, false))
throw data_ended_error();
return {key_factory->create(pt.get("key", "")),
value_factory->create(pt.get("value", ""))};
}
get_key_value_from_json(const std::string &data, std::unique_ptr<KeyValueTypeFactory> &key_factory,
std::unique_ptr<KeyValueTypeFactory> &value_factory) {
boost::property_tree::ptree pt{};

std::stringstream ss(data);

boost::property_tree::json_parser::read_json(ss, pt);

if (pt.get(data_end_flag, false))
throw data_ended_error();

return {key_factory->create(pt.get("key", "")),
value_factory->create(pt.get("value", ""))};
}



std::string
to_csv(const std::vector<std::pair<std::unique_ptr<KeyValueType>, std::unique_ptr<KeyValueType>>> &key_values,
Expand Down