2020#include < limits>
2121
2222template <typename T>
23- T wasm::read_file (const std::string &filename, bool debug) {
23+ T wasm::read_file (const std::string &filename, bool binary, bool debug) {
2424 if (debug) std::cerr << " Loading '" << filename << " '..." << std::endl;
25- std::ifstream infile (filename);
25+ std::ifstream infile;
26+ auto flags = std::ifstream::in;
27+ if (binary) flags |= std::ifstream::binary;
28+ infile.open (filename, flags);
2629 if (!infile.is_open ()) {
2730 std::cerr << " Failed opening '" << filename << " '" << std::endl;
2831 exit (EXIT_FAILURE );
@@ -41,15 +44,17 @@ T wasm::read_file(const std::string &filename, bool debug) {
4144}
4245
4346// Explicit instantiations for the explicit specializations.
44- template std::string wasm::read_file<>(const std::string &, bool );
45- template std::vector<char > wasm::read_file<>(const std::string &, bool );
47+ template std::string wasm::read_file<>(const std::string &, bool , bool );
48+ template std::vector<char > wasm::read_file<>(const std::string &, bool , bool );
4649
47- wasm::Output::Output (const std::string &filename, bool debug)
48- : outfile(), out([this , filename, debug]() {
50+ wasm::Output::Output (const std::string &filename, bool binary, bool debug)
51+ : outfile(), out([this , filename, binary, debug]() {
4952 std::streambuf *buffer;
5053 if (filename.size ()) {
5154 if (debug) std::cerr << " Opening '" << filename << std::endl;
52- outfile.open (filename, std::ofstream::out | std::ofstream::trunc);
55+ auto flags = std::ofstream::out | std::ofstream::trunc;
56+ if (binary) flags |= std::ofstream::binary;
57+ outfile.open (filename, flags);
5358 if (!outfile.is_open ()) {
5459 std::cerr << " Failed opening '" << filename << " '" << std::endl;
5560 exit (EXIT_FAILURE );
0 commit comments