mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpiutil] Return wpi::expected from MemoryBuffer::GetFile (#7069)
This commit is contained in:
@@ -259,10 +259,14 @@ static std::unique_ptr<WritableMemoryBuffer> GetMemoryBufferForStream(
|
||||
return GetMemBufferCopyImpl(buffer, bufferName, ec);
|
||||
}
|
||||
|
||||
std::unique_ptr<MemoryBuffer> MemoryBuffer::GetFile(std::string_view filename,
|
||||
std::error_code& ec,
|
||||
int64_t fileSize) {
|
||||
return GetFileAux<MemoryBuffer>(filename, ec, fileSize, fileSize, 0);
|
||||
wpi::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
|
||||
MemoryBuffer::GetFile(std::string_view filename, int64_t fileSize) {
|
||||
std::error_code ec;
|
||||
auto ret = GetFileAux<MemoryBuffer>(filename, ec, fileSize, fileSize, 0);
|
||||
if (ec) {
|
||||
return wpi::unexpected{ec};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename MB>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
#include <wpi/expected>
|
||||
|
||||
// Duplicated from fs.h to avoid a dependency
|
||||
namespace fs {
|
||||
@@ -77,9 +78,8 @@ class MemoryBuffer {
|
||||
/// if successful, otherwise returning null. If FileSize is specified, this
|
||||
/// means that the client knows that the file exists and that it has the
|
||||
/// specified size.
|
||||
static std::unique_ptr<MemoryBuffer> GetFile(std::string_view filename,
|
||||
std::error_code& ec,
|
||||
int64_t fileSize = -1);
|
||||
static wpi::expected<std::unique_ptr<MemoryBuffer>, std::error_code>
|
||||
GetFile(std::string_view filename, int64_t fileSize = -1);
|
||||
|
||||
/// Read all of the specified file into a MemoryBuffer as a stream
|
||||
/// (i.e. until EOF reached). This is useful for special files that
|
||||
|
||||
Reference in New Issue
Block a user