From baa52d3baac17571c453ef46edc8d3713473a15c Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Tue, 18 Feb 2025 19:02:33 +0100 Subject: [PATCH] databuffer --- include/sp/common/DataBuffer.h | 4 ++-- src/sp/common/DataBuffer.cpp | 34 +++++++++++----------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/include/sp/common/DataBuffer.h b/include/sp/common/DataBuffer.h index 7c1f063..32ac95b 100644 --- a/include/sp/common/DataBuffer.h +++ b/include/sp/common/DataBuffer.h @@ -261,13 +261,13 @@ class DataBuffer { * \brief Read a file into the buffer * \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 * \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 diff --git a/src/sp/common/DataBuffer.cpp b/src/sp/common/DataBuffer.cpp index 36975c5..00d8335 100644 --- a/src/sp/common/DataBuffer.cpp +++ b/src/sp/common/DataBuffer.cpp @@ -130,31 +130,19 @@ std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer) { return os; } -bool DataBuffer::ReadFile(const std::string& fileName) { - try { - std::ifstream file(fileName, std::istream::binary); - std::ostringstream ss; - ss << file.rdbuf(); - const std::string& s = ss.str(); - m_Buffer = DataBuffer::Data(s.begin(), s.end()); - 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; +void DataBuffer::ReadFile(const std::string& fileName) { + std::ifstream file(fileName, std::istream::binary); + std::ostringstream ss; + ss << file.rdbuf(); + const std::string& s = ss.str(); + m_Buffer = DataBuffer::Data(s.begin(), s.end()); + m_ReadOffset = 0; } -bool DataBuffer::WriteFile(const std::string& fileName) const { - try { - std::ofstream file(fileName, std::ostream::binary); - file.write(reinterpret_cast(m_Buffer.data()), static_cast(m_Buffer.size())); - 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; +void DataBuffer::WriteFile(const std::string& fileName) const { + std::ofstream file(fileName, std::ostream::binary); + file.write(reinterpret_cast(m_Buffer.data()), static_cast(m_Buffer.size())); + file.flush(); } } // namespace sp