diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-08-17 12:32:50 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-08-17 12:32:50 +0200 |
| commit | 375799fa79d1af76f33299acc20a11a167a021f8 (patch) | |
| tree | 8f91b982ec96225c33a2f4871730ababffe5cab0 /source/lib/include/wanda/magic.hpp | |
| parent | af471b9b780869915d3217b228e24d025892de47 (diff) | |
| download | wanda-375799fa79d1af76f33299acc20a11a167a021f8.tar.xz wanda-375799fa79d1af76f33299acc20a11a167a021f8.zip | |
project: restructure libraries and build env
Diffstat (limited to 'source/lib/include/wanda/magic.hpp')
| -rw-r--r-- | source/lib/include/wanda/magic.hpp | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/source/lib/include/wanda/magic.hpp b/source/lib/include/wanda/magic.hpp deleted file mode 100644 index fcb153e..0000000 --- a/source/lib/include/wanda/magic.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef WANDA_MAGIC_HPP -#define WANDA_MAGIC_HPP - -#include <magic.h> - -#include <filesystem> -#include <memory> -#include <string> -#include <type_traits> - -namespace wanda -{ - struct magic - { - struct closer - { - auto operator()(magic_t handle) const noexcept -> void - { - magic_close(handle); - } - }; - - enum struct mime_type - { - unknown, - image_jpeg, - image_png, - }; - - magic() - : m_handle{magic_open(MAGIC_MIME_TYPE)} - { - magic_load(m_handle.get(), nullptr); - } - - auto type(std::filesystem::path path) -> mime_type - { - auto magic_type = std::string{magic_file(m_handle.get(), path.native().c_str())}; - - if (magic_type == "image/jpeg") - { - return mime_type::image_jpeg; - } - else if (magic_type == "image/png") - { - return mime_type::image_png; - } - - return mime_type::unknown; - } - - private: - std::unique_ptr<std::remove_pointer_t<magic_t>, closer> m_handle; - }; - -} // namespace wanda - -#endif
\ No newline at end of file |
