Adapted to design changes in file_reader

This commit is contained in:
luna 2025-07-24 05:10:28 +02:00
parent c62f43c931
commit 41facff9c5
3 changed files with 28 additions and 3 deletions

@ -1 +1 @@
Subproject commit 1d370096d9b0767627566191be1e5526a5c90238
Subproject commit 54a063d5e6ab8ea06b1101154574d2eaeebbde5f

View file

@ -7,7 +7,10 @@ static std::expected<bool, lily_png::png_error> read_raw_data(const std::string
{
std::println("Zlib version is {}", zlibVersion());
unsigned char magic[9] = {137, 80, 78, 71, 13, 10, 26, 10};
file_reader::file_reader reader(file_path);
file_reader::file_reader reader{};
auto result = reader.open_file(file_path);
if (!result)
return std::unexpected(lily_png::png_error::file_doesnt_exist);
char file_magic[9] = {0};
auto res = reader.read_buffer(file_magic, 8).or_else([](const file_reader::RESULT &res)
{

View file

@ -3,6 +3,7 @@
#include "../file_reader/src/file_read.h"
#include <string>
#include <vector>
#include <format>
#include "utils.h"
#include "filter.h"
#include <zlib.h>
@ -24,5 +25,26 @@ namespace lily_png
};
std::expected<metadata, png_error> read_png(const std::string &file_path, file_reader::buffer<unsigned char> &data);
}
template <>
struct std::formatter<lily_png::png_error>
{
constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin();
}
auto format(const lily_png::png_error& id, std::format_context& ctx) const
{
if (id == lily_png::png_error::file_doesnt_exist)
return std::format_to(ctx.out(), "{}", "File doesn't exist");
if (id == lily_png::png_error::read_failed)
return std::format_to(ctx.out(), "{}", "Read failed");
if (id == lily_png::png_error::file_is_not_a_png)
return std::format_to(ctx.out(), "{}", "File is not a png");
return std::format_to(ctx.out(), "{}", "Unkown error");
}
};