| 5883 | |
| 5884 | #ifdef LODEPNG_COMPILE_DISK |
| 5885 | void load_file(std::vector<unsigned char>& buffer, const std::string& filename) |
| 5886 | { |
| 5887 | std::ifstream file(filename.c_str(), std::ios::in|std::ios::binary|std::ios::ate); |
| 5888 | |
| 5889 | /*get filesize*/ |
| 5890 | std::streamsize size = 0; |
| 5891 | if(file.seekg(0, std::ios::end).good()) size = file.tellg(); |
| 5892 | if(file.seekg(0, std::ios::beg).good()) size -= file.tellg(); |
| 5893 | |
| 5894 | /*read contents of the file into the vector*/ |
| 5895 | buffer.resize(size_t(size)); |
| 5896 | if(size > 0) file.read((char*)(&buffer[0]), size); |
| 5897 | } |
| 5898 | |
| 5899 | /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ |
| 5900 | void save_file(const std::vector<unsigned char>& buffer, const std::string& filename) |