Files
FEX-Emu--FEX/External/FEXCore/Source/Utils/FileLoading.h
T
Ryan Houdek f36bbf0f59 FileLoading: Add a very quick fixed size small file loading helper
If we have a fixed file to read, we can read it in three syscalls.
fstream is...weirdly slow in the other implementation.

Theoretically in the future this can be improved to a single syscall if
the `readfile` syscall ends up in upstream Linux.
2023-01-14 13:33:32 -08:00

30 lines
827 B
C++

#pragma once
#include <string>
#include <vector>
#include <filesystem>
#include <fstream>
#include <span>
namespace FEXCore::FileLoading {
/**
* @brief Loads a filepath in to a vector of data
*
* @param Data The vector to load the file data in to
* @param Filepath The filepath to load
*
* @return true on file loaded, false on failure
*/
bool LoadFile(std::vector<char> &Data, const std::string &Filepath, size_t FixedSize = 0);
/**
* @brief Loads a filepath in to a buffer of data with a fixed size
*
* @param Filepath The filepath to load
* @param Buffer The buffer to load the data in to. Attempting to read the full size of the span
*
* @return The amount of data read or -1 on error.
*/
ssize_t LoadFileToBuffer(const std::string &Filepath, std::span<char> Buffer);
}