void merge(std::string& filesPath, std::string& outPutFilePath) {
namespace fs = std::filesystem;
std::set<fs::path> files_to_merge;
std::ofstream merged_file;
fs::path split_path = fs::path(filesPath);
for (const auto& file : fs::directory_iterator(split_path)) {
files_to_merge.insert((fs::path)file);
}
std::ofstream ofile(outPutFilePath,std::ios::out|std::ios::app|std::ios::binary);
ofile.unsetf(std::ios_base::skipws);
for (auto& file : files_to_merge) {
std::ifstream ifile(file, std::ios::in | std::ios::binary);
if (!ifile.is_open())
{
throw invalid_file("could not read file: ");
break;
}
ifile.unsetf(std::ios_base::skipws);
std::copy(std::istream_iterator<char> (ifile),
std::istream_iterator<char>(),
std::ostream_iterator<char> (ofile));
//ofile << ifile.rdbuf();
}
}
split_path is path to splits of bigger file. The code actually merges. The problem is it inserts a new line between 2 file parts.The insertion of new line may not problem for human beings. But when the merged file is encrypted file, the decryption algorithm fails due the inserted new line[s]. Is there a way to replicate original file when merging?
Aucun commentaire:
Enregistrer un commentaire