diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-06-04 19:58:56 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-06-04 19:58:56 +0200 |
| commit | 7832816c0d239c1cd7a91daef3f15c8f94197e28 (patch) | |
| tree | d1de8dec25496a3a98234644a60d5c6f98140f06 /cabinet/magic.cpp | |
| parent | 11df846b1ec951dd35feb9b0bad42486c7b94dca (diff) | |
| download | cabinet-7832816c0d239c1cd7a91daef3f15c8f94197e28.tar.xz cabinet-7832816c0d239c1cd7a91daef3f15c8f94197e28.zip | |
magic: implement file processing
Diffstat (limited to 'cabinet/magic.cpp')
| -rw-r--r-- | cabinet/magic.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/cabinet/magic.cpp b/cabinet/magic.cpp index 96e212f..b5c1aaa 100644 --- a/cabinet/magic.cpp +++ b/cabinet/magic.cpp @@ -4,6 +4,8 @@ #include <cerrno> #include <expected> +#include <filesystem> +#include <string> #include <string_view> #include <system_error> #include <utility> @@ -51,6 +53,16 @@ namespace cab return *this; } + auto magic::process(std::filesystem::path path) -> std::expected<std::string, std::string> + { + auto result = ::magic_file(m_cookie, path.native().c_str()); + if (!result) + { + return std::unexpected{std::string{::magic_error(m_cookie)}}; + } + return result; + } + auto swap(magic & lhs, magic & rhs) noexcept -> void { auto temp = std::move(lhs); |
