[ox/fs] Add Result<Vector<char>> FileSystem::read

This commit is contained in:
Gary Talent 2021-04-21 00:05:37 -05:00
parent 863437fb10
commit 4540b410dc
2 changed files with 11 additions and 0 deletions

View File

@ -6,6 +6,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ox/std/utility.hpp>
#include "filesystem.hpp"
namespace ox {
@ -34,6 +36,13 @@ Error FileSystem::read(FileAddress addr, void *buffer, std::size_t size) noexcep
}
}
Result<Vector<char>> FileSystem::read(FileAddress addr) noexcept {
oxRequire(s, stat(addr));
ox::Vector<char> buff(s.size);
oxReturnError(read(addr, buff.data(), buff.size()));
return ox::move(buff);
}
Error FileSystem::read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept {
switch (addr.type()) {
case FileAddressType::Inode:

View File

@ -42,6 +42,8 @@ class FileSystem {
Error read(FileAddress addr, void *buffer, std::size_t size) noexcept;
Result<Vector<char>> read(FileAddress addr) noexcept;
Error read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept;
Result<const uint8_t*> directAccess(FileAddress addr) noexcept;