39 lines
1017 B
C++
39 lines
1017 B
C++
#include <Orange/Core/FileSystem.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
namespace orange::fs
|
|
{
|
|
Result<Buffer> OpenFileIntoBuffer(const char* path)
|
|
{
|
|
FILE* file = fopen(path, "rb");
|
|
if (!file)
|
|
Result<Buffer>::Error(BasicErrorCode::NotFound);
|
|
fseek(file, 0, SEEK_END);
|
|
size_t size = size_t(ftell(file));
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
uint8_t* data = new uint8_t[size];
|
|
fread(data, size, 1, file);
|
|
fclose(file);
|
|
|
|
return Result<Buffer>::Success(data, size);
|
|
}
|
|
|
|
Result<TextBuffer> OpenFileIntoTextBuffer(const char* path)
|
|
{
|
|
FILE* file = fopen(path, "rb");
|
|
if (!file)
|
|
Result<TextBuffer>::Error(BasicErrorCode::NotFound);
|
|
fseek(file, 0, SEEK_END);
|
|
size_t size = size_t(ftell(file));
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
char* data = new char[size];
|
|
fread(data, size, 1, file);
|
|
fclose(file);
|
|
|
|
return Result<TextBuffer>::Success(data, size);
|
|
}
|
|
}
|