// TJP COPYRIGHT HEADER #ifdef TJP_CORE_HEADER_ONLY #pragma once #endif #include #include "read.hpp" #include #include #include namespace tjp::core::file { TJP_CORE_HEADER_ONLY_INLINE Optional read(const String& path) { std::ifstream file(path, std::ios::ate | std::ios::binary); bool exists = (bool)file; if (!exists || !file.is_open()) return {}; size_t fileSize = (size_t)file.tellg(); Contents buffer(fileSize); file.seekg(0); file.read(buffer.data(), buffer.size()); file.close(); return buffer; }; TJP_CORE_HEADER_ONLY_INLINE Contents require_read(const String& path) { if (auto result = read(path)) return *result; throw Exception { "failed to read file " + String(path) }; } TJP_CORE_HEADER_ONLY_INLINE Optional read(const StringView& path) { return read(String(path)); } TJP_CORE_HEADER_ONLY_INLINE Contents require_read(const StringView& path) { return require_read(String(path)); } } // namespace