| 693 | } |
| 694 | |
| 695 | vector<unsigned char> readFile(const char* filename) { |
| 696 | /* |
| 697 | TODO: Fix this faster variant |
| 698 | vector<unsigned char> vec; |
| 699 | ifstream in(filename, ios::in | ios::binary); |
| 700 | if (in) |
| 701 | { |
| 702 | string contents; |
| 703 | in.seekg(0, ios::end); |
| 704 | vec.resize(in.tellg()); |
| 705 | in.seekg(0, ios::beg); |
| 706 | in.read(&contents[0], contents.size()); |
| 707 | in.close(); |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | LOGF << "Unable to read file" << filename << endl; |
| 712 | } |
| 713 | return vec; |
| 714 | */ |
| 715 | |
| 716 | // open the file: |
| 717 | vector<unsigned char> vec; |
| 718 | |
| 719 | if (isFile(filename)) { |
| 720 | ifstream file; |
| 721 | my_ifstream_open(file, filename, ios::binary); |
| 722 | |
| 723 | if (file.good()) { |
| 724 | // Stop eating new lines in binary mode!!! |
| 725 | file.unsetf(ios::skipws); |
| 726 | |
| 727 | // get its size: |
| 728 | streampos fileSize; |
| 729 | |
| 730 | file.seekg(0, ios::end); |
| 731 | fileSize = file.tellg(); |
| 732 | file.seekg(0, ios::beg); |
| 733 | |
| 734 | // reserve capacity |
| 735 | vec.reserve(fileSize); |
| 736 | |
| 737 | // read the data: |
| 738 | vec.insert(vec.begin(), |
| 739 | istream_iterator<unsigned char>(file), |
| 740 | istream_iterator<unsigned char>()); |
| 741 | } else { |
| 742 | LOGE << "Unable to read file " << filename << endl; |
| 743 | } |
| 744 | file.close(); |
| 745 | } |
| 746 | |
| 747 | return vec; |
| 748 | } |
| 749 | |
| 750 | void CreateParentDirs(const string& abs_path) { |
| 751 | CreateParentDirs(abs_path.c_str()); |
no test coverage detected