diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-10 15:55:54 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-10 16:49:13 +0100 |
commit | 2f3b901f7fe230cbbf489f5a0f38fbb34a07af8c (patch) | |
tree | ceff5568f544c8bc2ef10857a914c17044863339 /Services | |
parent | 70fce5c4c7279c045e593a8a3a6f79ebc28e2972 (diff) | |
download | serenity-2f3b901f7fe230cbbf489f5a0f38fbb34a07af8c.zip |
AK: Make MappedFile heap-allocated and ref-counted
Let's adapt this class a bit better to how it's actually being used.
Instead of having valid/invalid states and storing an error in case
it's invalid, a MappedFile is now always valid, and the factory
function that creates it will return an OSError if mapping fails.
Diffstat (limited to 'Services')
-rw-r--r-- | Services/WebServer/Client.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Services/WebServer/Client.cpp b/Services/WebServer/Client.cpp index deb582e013..84ba323d64 100644 --- a/Services/WebServer/Client.cpp +++ b/Services/WebServer/Client.cpp @@ -162,8 +162,9 @@ static String folder_image_data() { static String cache; if (cache.is_empty()) { - MappedFile image("/res/icons/16x16/filetype-folder.png"); - cache = encode_base64({ image.data(), image.size() }); + auto file_or_error = MappedFile::map("/res/icons/16x16/filetype-folder.png"); + ASSERT(!file_or_error.is_error()); + cache = encode_base64(file_or_error.value()->bytes()); } return cache; } @@ -172,8 +173,9 @@ static String file_image_data() { static String cache; if (cache.is_empty()) { - MappedFile image("/res/icons/16x16/filetype-unknown.png"); - cache = encode_base64({ image.data(), image.size() }); + auto file_or_error = MappedFile::map("/res/icons/16x16/filetype-unknown.png"); + ASSERT(!file_or_error.is_error()); + cache = encode_base64(file_or_error.value()->bytes()); } return cache; } |