diff --git a/src/bakatools/file_system/file.cpp b/src/bakatools/file_system/file.cpp index 56351a1..45c06b0 100644 --- a/src/bakatools/file_system/file.cpp +++ b/src/bakatools/file_system/file.cpp @@ -10,4 +10,27 @@ namespace Bk::Tools { { if (exists()) std::filesystem::copy_file(ent.path(), path, opt); } + + DataStream File::read(int size) + { + std::vector data; + if(exists()) + { + std::ifstream ifrm(ent.path(), std::ios::binary); + data.resize(size); + ifrm.read(data.data(), data.size()); + return DataStream(data); + } + } + + bool File::write(DataStream stream) + { + try + { + std::ofstream ofrm(ent.path(), std::ios::binary); + ofrm.write(stream.payload.data(), stream.payload.size()); + return true; + } catch return false; + + } } \ No newline at end of file diff --git a/src/bakatools/file_system/file.h b/src/bakatools/file_system/file.h index cd6b637..aa50c08 100644 --- a/src/bakatools/file_system/file.h +++ b/src/bakatools/file_system/file.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "dir_entry.h" namespace Bk::Tools { @@ -19,6 +20,9 @@ namespace Bk::Tools { int remove() override; void copy(std::string path, CopyOption opt = CopyOption::overwrite_existing) override; + DataStream read(int size = size()); + bool write(DataStream stream); + BK_DIR_ENTRY_TYPE(regular) }; } \ No newline at end of file