From 04a4da318844da366f77e0230ea980928e2e4116 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 22 Mar 2025 13:08:11 +0100 Subject: [PATCH] Support std::byte in I/O util --- src/common/utils/io.cpp | 7 ++++++- src/common/utils/io.hpp | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/utils/io.cpp b/src/common/utils/io.cpp index 6c4899b5..a43190f8 100644 --- a/src/common/utils/io.cpp +++ b/src/common/utils/io.cpp @@ -21,7 +21,7 @@ namespace utils::io return std::ifstream(file).good(); } - bool write_file(const std::filesystem::path& file, const std::vector& data, const bool append) + bool write_file(const std::filesystem::path& file, const std::span data, const bool append) { if (file.has_parent_path()) { @@ -41,6 +41,11 @@ namespace utils::io return false; } + bool write_file(const std::filesystem::path& file, const std::span data, const bool append) + { + return write_file(file, std::span(reinterpret_cast(data.data()), data.size()), append); + } + std::vector read_file(const std::filesystem::path& file) { std::vector data; diff --git a/src/common/utils/io.hpp b/src/common/utils/io.hpp index 38ae1df6..69bdb975 100644 --- a/src/common/utils/io.hpp +++ b/src/common/utils/io.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -9,7 +9,8 @@ namespace utils::io bool remove_file(const std::filesystem::path& file); bool move_file(const std::filesystem::path& src, const std::filesystem::path& target); bool file_exists(const std::filesystem::path& file); - bool write_file(const std::filesystem::path& file, const std::vector& data, bool append = false); + bool write_file(const std::filesystem::path& file, std::span data, bool append = false); + bool write_file(const std::filesystem::path& file, std::span data, bool append = false); bool read_file(const std::filesystem::path& file, std::vector* data); std::vector read_file(const std::filesystem::path& file); size_t file_size(const std::filesystem::path& file);