60 std::filesystem::path,
68 enum flags :
unsigned long long {
211 [[nodiscard]] operator
bool() const noexcept;
230 void close() noexcept;
281 [[nodiscard]] static std::
string get_version() noexcept;
305 const std::filesystem::path& path,
322 const std::filesystem::path& directory,
323 std::filesystem::directory_options option = std::filesystem::
324 directory_options::follow_directory_symlink
328 std::filesystem::recursive_directory_iterator{directory, option}
341 const std::filesystem::path& directory,
343 std::filesystem::directory_options option = std::filesystem::
344 directory_options::follow_directory_symlink
348 std::filesystem::recursive_directory_iterator{directory, option},
391 [[nodiscard]]
bool is_open() const noexcept;
477 const std::ranges::range auto& files
481 std::ranges::for_each(files, [&](
const std::filesystem::path& file) {
484 return types_of_files;
488 const std::ranges::range
auto& files,
493 std::ranges::for_each(files, [&](
const std::filesystem::path& file) {
494 expected_types_of_files[file] =
identify_file(file, std::nothrow);
496 return expected_types_of_files;
514 const std::string& type_separator =
" -> ",
515 const std::string& file_separator =
"\n"
540 const std::string& type_separator =
" -> ",
541 const std::string& file_separator =
"\n"
563 const std::string& separator =
", "
586 const std::string& value_separator =
": ",
587 const std::string& parameter_separator =
", "
The magic class provides a C++ wrapper over the Magic Number Recognition Library.
Definition magic.hpp:29
bool is_open() const noexcept
Used for testing whether magic is open or closed.
Definition magic.cpp:609
void set_flags(flags_mask_t flags_mask)
Set the flags of magic.
Definition magic.cpp:629
bool compile(const std::filesystem::path &database_file=default_database_file) const noexcept
Compile the colon separated list of database files passed in as database_file.
Definition magic.cpp:568
void set_parameters(const parameter_value_map_t ¶meters)
Set the values of the parameters of magic.
Definition magic.cpp:644
std::size_t get_parameter(parameters parameter) const
Get the value of a parameter of magic.
Definition magic.cpp:578
std::unique_ptr< magic_private > m_impl
Definition magic.hpp:474
std::string error_message_t
The error_message_t typedef.
Definition magic.hpp:44
flags_container_t get_flags() const
Get the flags of magic.
Definition magic.cpp:573
flags
The flags enums are used for configuring the flags of a magic.
Definition magic.hpp:68
@ raw
Definition magic.hpp:79
@ no_check_tokens
Definition magic.hpp:96
@ no_check_cdf
Definition magic.hpp:94
@ symlink
Definition magic.hpp:72
@ no_check_apptype
Definition magic.hpp:91
@ error
Definition magic.hpp:80
@ no_check_compress
Definition magic.hpp:88
@ no_check_tar
Definition magic.hpp:89
@ mime_type
Definition magic.hpp:75
@ mime_encoding
Definition magic.hpp:81
@ debug
Definition magic.hpp:71
@ no_check_elf
Definition magic.hpp:92
@ none
Definition magic.hpp:70
@ nodesc
Definition magic.hpp:87
@ compress_transp
Definition magic.hpp:85
@ apple
Definition magic.hpp:83
@ mime
Definition magic.hpp:82
@ compress
Definition magic.hpp:73
@ no_check_text
Definition magic.hpp:93
@ no_check_soft
Definition magic.hpp:90
@ no_compress_fork
Definition magic.hpp:86
@ preserve_atime
Definition magic.hpp:78
@ no_check_builtin
Definition magic.hpp:100
@ extension
Definition magic.hpp:84
@ devices
Definition magic.hpp:74
@ no_check_encoding
Definition magic.hpp:97
@ no_check_simh
Definition magic.hpp:99
@ no_check_csv
Definition magic.hpp:95
@ continue_search
Definition magic.hpp:76
@ check_database
Definition magic.hpp:77
@ no_check_json
Definition magic.hpp:98
magic() noexcept
Construct magic without opening it.
Definition magic.cpp:523
void open(flags_mask_t flags_mask)
Open magic using the flags.
Definition magic.cpp:619
std::map< std::filesystem::path, expected_file_type_t > expected_types_of_files_t
The expected_types_of_files_t typedef.
Definition magic.hpp:59
bool check(const std::filesystem::path &database_file=default_database_file) const noexcept
check the validity of entries in the colon separated database files passed in as database_file.
Definition magic.cpp:558
std::bitset< 30uz > flags_mask_t
The flags_mask_t typedef.
Definition magic.hpp:34
std::vector< flags > flags_container_t
The flags_container_t typedef.
Definition magic.hpp:126
file_type_t identify_file(const std::filesystem::path &path) const
Identify the type of a file.
Definition magic.cpp:594
parameters
The parameters enums are used for displaying or modifying the parameters of a magic.
Definition magic.hpp:108
expected_types_of_files_t identify_files(const std::filesystem::path &directory, std::nothrow_t, std::filesystem::directory_options option=std::filesystem::directory_options::follow_directory_symlink) const noexcept
Identify the types of all files in a directory, noexcept version.
Definition magic.hpp:340
void set_parameter(parameters parameter, std::size_t value)
Set the value of a parameter of magic.
Definition magic.cpp:639
types_of_files_t identify_files(const file_concepts::file_container auto &files) const
Identify the types of files.
Definition magic.hpp:364
static std::string_view default_database_file
The path of the default database file.
Definition magic.hpp:136
std::map< parameters, std::size_t > parameter_value_map_t
The parameter_value_map_t typedef.
Definition magic.hpp:131
std::expected< file_type_t, error_message_t > expected_file_type_t
The expected_file_type_t typedef.
Definition magic.hpp:49
std::string file_type_t
The file_type_t typedef.
Definition magic.hpp:39
std::map< std::filesystem::path, file_type_t > types_of_files_t
The types_of_files_t typedef.
Definition magic.hpp:54
void close() noexcept
Close magic.
Definition magic.cpp:563
friend std::string to_string(flags)
Convert the magic::flags to string.
Definition magic.cpp:470
void load_database_file(const std::filesystem::path &database_file=default_database_file)
Load a magic database file.
Definition magic.cpp:614
parameter_value_map_t get_parameters() const
Get the values of all parameters of magic.
Definition magic.cpp:584
expected_types_of_files_t identify_files_impl(const std::ranges::range auto &files, std::nothrow_t) const noexcept
Definition magic.hpp:487
types_of_files_t identify_files_impl(const std::ranges::range auto &files) const
Definition magic.hpp:476
types_of_files_t identify_files(const std::filesystem::path &directory, std::filesystem::directory_options option=std::filesystem::directory_options::follow_directory_symlink) const
Identify the types of all files in a directory.
Definition magic.hpp:321
static std::string get_version() noexcept
Get the version of the Magic Number Recognition Library.
Definition magic.cpp:589
expected_types_of_files_t identify_files(const file_concepts::file_container auto &files, std::nothrow_t) const noexcept
Identify the types of files, noexcept version.
Definition magic.hpp:378
The file_container concept specifies the requirements of a container which can be used as a file cont...
Definition file_concepts.hpp:18
std::string to_string(const magic::types_of_files_t &types_of_files, const std::string &type_separator=" -> ", const std::string &file_separator="\n")
Convert the magic::types_of_files_t to string.
Definition magic.cpp:423