-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
k-okawa
committed
Jul 5, 2021
1 parent
53ca804
commit 00409cf
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Created by kyohei.okawa on 2021/07/05. | ||
// | ||
|
||
#ifndef STEGANOGRAPHY_FILEUTIL_H | ||
#define STEGANOGRAPHY_FILEUTIL_H | ||
|
||
#include <stdio.h> | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
namespace FileUtil { | ||
|
||
std::vector<std::byte> Read(std::string path) { | ||
std::ifstream ifs(path, std::ios::binary); | ||
if (ifs.fail()) { | ||
std::cerr << "Failed to open file" << std::endl; | ||
return std::vector<std::byte>(); | ||
} | ||
|
||
|
||
ifs.seekg(0, std::ios::end); | ||
long long int size = ifs.tellg(); | ||
ifs.seekg(0); | ||
|
||
char *data = new char[size]; | ||
ifs.read(data, size); | ||
std::vector<std::byte> ret; | ||
for (int i = 0; i < size; i++) { | ||
ret.push_back((std::byte) data[i]); | ||
} | ||
delete[] data; | ||
|
||
ifs.close(); | ||
return ret; | ||
} | ||
|
||
void Write(std::vector<std::byte> data, std::string path) { | ||
std::ofstream fout(path, std::ios::out | std::ios::binary | std::ios::trunc); | ||
|
||
if (fout.fail()) { | ||
std::cerr << "Failed to open file" << std::endl; | ||
return; | ||
} | ||
|
||
for(int i = 0; i < data.size(); i++) { | ||
fout.write((char *)&data[i], sizeof(std::byte)); | ||
} | ||
|
||
fout.close(); | ||
} | ||
|
||
} | ||
|
||
#endif //STEGANOGRAPHY_FILEUTIL_H |