5 #ifndef POCKETLZMA_FILE_HPP
6 #define POCKETLZMA_FILE_HPP
16 static inline std::vector<uint8_t>
FromMemory(
const void *data,
size_t size);
17 static inline void FromMemory(
const void *data,
size_t size, std::vector<uint8_t> &output);
19 static inline std::vector<uint8_t>
FromFile(
const std::string &path);
20 static inline FileStatus FromFile(
const std::string &path, std::vector<uint8_t> &output);
22 static inline FileStatus ToFile(
const std::string &path,
const std::vector<uint8_t> &data);
27 std::vector<uint8_t> bytes(size);
36 mem.read((
char *)&output[0], size);
42 file = std::fstream(path, std::ios::in | std::ios::binary);
45 file.seekg(0, std::ios::end);
46 size_t fileSize = file.tellg();
47 file.seekg(0, std::ios::beg);
49 std::vector<uint8_t> bytes(fileSize);
51 file.read((
char *)&bytes[0], fileSize);
62 file = std::fstream(path, std::ios::in | std::ios::binary);
63 file.exceptions(std::fstream::failbit | std::fstream::badbit);
64 bool isBad = file.bad();
65 bool isFail = file.fail();
66 bool isOpen = file.is_open();
68 if(isBad || isFail || !isOpen)
79 file.seekg(0, std::ios::end);
80 size_t fileSize = file.tellg();
81 file.seekg(0, std::ios::beg);
83 output.resize(fileSize);
85 file.read((
char *) &output[0], fileSize);
90 catch (
const std::fstream::failure &e)
102 file.exceptions(std::fstream::failbit | std::fstream::badbit);
106 file = std::fstream(path, std::ios::out | std::ios::binary);
107 bool isBad = file.bad();
108 bool isFail = file.fail();
109 bool isOpen = file.is_open();
111 if(isBad || isFail || !isOpen)
121 for (
const auto &b : data)
127 catch (
const std::fstream::failure &e)
137 #endif //POCKETLZMA_FILE_HPP