better with obs forms
[ghsmtp.git] / Magic.cpp
blob975dd22b6f95bb4bfa093b2a37951317a7adea34
1 #include "Magic.hpp"
3 #include <magic.h>
5 #include <glog/logging.h>
7 Magic::Magic()
8 : magic_(CHECK_NOTNULL(magic_open(MAGIC_MIME)))
10 CHECK_EQ(magic_load(magic_, nullptr), 0) << magic_error(magic_);
13 Magic::~Magic() { magic_close(magic_); }
15 std::string Magic::buffer(std::string_view bfr) const
17 auto const data = reinterpret_cast<void const*>(bfr.data());
18 return CHECK_NOTNULL(magic_buffer(magic_, data, bfr.size()));
21 std::string Magic::file(char const* path) const
23 return CHECK_NOTNULL(magic_file(magic_, path));