databuffer
This commit is contained in:
@@ -261,13 +261,13 @@ class DataBuffer {
|
|||||||
* \brief Read a file into the buffer
|
* \brief Read a file into the buffer
|
||||||
* \param fileName The name of the file to read
|
* \param fileName The name of the file to read
|
||||||
*/
|
*/
|
||||||
bool ReadFile(const std::string& fileName);
|
void ReadFile(const std::string& fileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Write a file into the buffer
|
* \brief Write a file into the buffer
|
||||||
* \param fileName The name of the file to write to
|
* \param fileName The name of the file to write to
|
||||||
*/
|
*/
|
||||||
bool WriteFile(const std::string& fileName) const;
|
void WriteFile(const std::string& fileName) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Allocate the buffer on the heap
|
* \brief Allocate the buffer on the heap
|
||||||
|
|||||||
@@ -130,31 +130,19 @@ std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer) {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DataBuffer::ReadFile(const std::string& fileName) {
|
void DataBuffer::ReadFile(const std::string& fileName) {
|
||||||
try {
|
std::ifstream file(fileName, std::istream::binary);
|
||||||
std::ifstream file(fileName, std::istream::binary);
|
std::ostringstream ss;
|
||||||
std::ostringstream ss;
|
ss << file.rdbuf();
|
||||||
ss << file.rdbuf();
|
const std::string& s = ss.str();
|
||||||
const std::string& s = ss.str();
|
m_Buffer = DataBuffer::Data(s.begin(), s.end());
|
||||||
m_Buffer = DataBuffer::Data(s.begin(), s.end());
|
m_ReadOffset = 0;
|
||||||
m_ReadOffset = 0;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
// utils::LOGE(utils::Format("[IO] Failed to read file %s ! reason : %s", fileName.c_str(), e.what()));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m_Buffer.size() > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DataBuffer::WriteFile(const std::string& fileName) const {
|
void DataBuffer::WriteFile(const std::string& fileName) const {
|
||||||
try {
|
std::ofstream file(fileName, std::ostream::binary);
|
||||||
std::ofstream file(fileName, std::ostream::binary);
|
file.write(reinterpret_cast<const char*>(m_Buffer.data()), static_cast<std::streamsize>(m_Buffer.size()));
|
||||||
file.write(reinterpret_cast<const char*>(m_Buffer.data()), static_cast<std::streamsize>(m_Buffer.size()));
|
file.flush();
|
||||||
file.flush();
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
// utils::LOGE(utils::Format("[IO] Failed to read file %s ! reason : %s", fileName.c_str(), e.what()));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
Reference in New Issue
Block a user