| 6039 | |
| 6040 | #ifdef LODEPNG_COMPILE_DISK |
| 6041 | void load_file(std::vector<unsigned char>& buffer, const std::string& filename) |
| 6042 | { |
| 6043 | std::ifstream file(filename.c_str(), std::ios::in|std::ios::binary|std::ios::ate); |
| 6044 | |
| 6045 | /*get filesize*/ |
| 6046 | std::streamsize size = 0; |
| 6047 | if(file.seekg(0, std::ios::end).good()) size = file.tellg(); |
| 6048 | if(file.seekg(0, std::ios::beg).good()) size -= file.tellg(); |
| 6049 | |
| 6050 | /*read contents of the file into the vector*/ |
| 6051 | buffer.resize(size_t(size)); |
| 6052 | if(size > 0) file.read((char*)(&buffer[0]), size); |
| 6053 | } |
| 6054 | |
| 6055 | /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ |
| 6056 | void save_file(const std::vector<unsigned char>& buffer, const std::string& filename) |