diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2023-04-30 19:39:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-30 19:39:04 -0400 |
| commit | 52e51863e9d2d3f312389026c2b9aa1c56474fa1 (patch) | |
| tree | 2e10d65086b89c7d511b264ba4b645e6c5031861 | |
| parent | cb6da2e5a70f22df309268d998b89869851f4a2d (diff) | |
Close files (#283)
* Close files
* headers
| -rw-r--r-- | ZAPDUtils/Utils/File.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ZAPDUtils/Utils/File.h b/ZAPDUtils/Utils/File.h index 7bc5d29..bf2bb69 100644 --- a/ZAPDUtils/Utils/File.h +++ b/ZAPDUtils/Utils/File.h @@ -1,8 +1,6 @@ #pragma once -#include <cstdio> #include <fstream> -#include <iostream> #include <string> #include <vector> #include "Directory.h" @@ -26,6 +24,7 @@ public: file.read(data, fileSize); std::vector<uint8_t> result = std::vector<uint8_t>(data, data + fileSize); delete[] data; + file.close(); return result; }; @@ -42,6 +41,7 @@ public: file.read(data, fileSize); std::string str = std::string((const char*)data); delete[] data; + file.close(); return str; }; @@ -58,23 +58,27 @@ public: { std::ofstream file(filePath, std::ios::binary); file.write((char*)data.data(), data.size()); + file.close(); }; static void WriteAllBytes(const std::string& filePath, const std::vector<char>& data) { std::ofstream file(filePath, std::ios::binary); file.write((char*)data.data(), data.size()); + file.close(); }; static void WriteAllBytes(const std::string& filePath, const char* data, int dataSize) { std::ofstream file(filePath, std::ios::binary); file.write((char*)data, dataSize); + file.close(); }; static void WriteAllText(const fs::path& filePath, const std::string& text) { std::ofstream file(filePath, std::ios::out); file.write(text.c_str(), text.size()); + file.close(); } }; |
