[wpiutil] Return wpi::expected from MemoryBuffer::GetFile (#7069)

This commit is contained in:
Joseph Eng
2024-09-12 23:45:35 -07:00
committed by GitHub
parent d44b651558
commit 1f3ef019ce
15 changed files with 87 additions and 103 deletions

View File

@@ -125,9 +125,8 @@ void HALSimHttpConnection::SendFileResponse(int code, std::string_view codeText,
}
// open file
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
wpi::MemoryBuffer::GetFile(filename, ec);
if (fileBuffer == nullptr || ec) {
auto fileBuffer = wpi::MemoryBuffer::GetFile(filename);
if (!fileBuffer) {
MySendError(404, "error opening file");
return;
}
@@ -143,7 +142,7 @@ void HALSimHttpConnection::SendFileResponse(int code, std::string_view codeText,
wpi::SmallVector<uv::Buffer, 4> bodyData;
wpi::raw_uv_ostream bodyOs{bodyData, 4096};
bodyOs << fileBuffer->GetBuffer();
bodyOs << fileBuffer.value()->GetBuffer();
SendData(bodyOs.bufs(), false);
if (!m_keepAlive) {