81 std::filesystem::path,
224 const std::nothrow_t& tag,
258 const std::nothrow_t& tag,
303 [[nodiscard]] operator
bool() const noexcept;
313 [[nodiscard]] static
bool check(
323 void close() noexcept;
336 [[nodiscard]] static
bool compile(
357 const std::nothrow_t& tag
381 const std::nothrow_t& tag
401 const std::nothrow_t& tag
409 [[nodiscard]] static std::
string get_version() noexcept;
436 const std::filesystem::path& path,
437 const std::nothrow_t& tag
457 const std::filesystem::path& directory,
458 std::filesystem::directory_options option = std::filesystem::
459 directory_options::follow_directory_symlink
484 const std::filesystem::path& directory,
486 std::filesystem::directory_options option = std::filesystem::
487 directory_options::follow_directory_symlink
503 const std::filesystem::path& directory,
504 const std::nothrow_t& tag,
505 std::filesystem::directory_options option = std::filesystem::
506 directory_options::follow_directory_symlink
523 const std::filesystem::path& directory,
524 const std::nothrow_t& tag,
526 std::filesystem::directory_options option = std::filesystem::
527 directory_options::follow_directory_symlink
551 {std::ranges::begin(files), std::ranges::end(files)}
576 {std::ranges::begin(files), std::ranges::end(files)},
591 const std::nothrow_t& tag
595 {std::ranges::begin(files), std::ranges::end(files)},
611 const std::nothrow_t& tag,
616 {std::ranges::begin(files), std::ranges::end(files)},
634 [[nodiscard]]
bool is_open() const noexcept;
644 [[nodiscard]]
bool is_valid() const noexcept;
674 const std::nothrow_t& tag,
701 [[nodiscard]]
bool open(
703 const std::nothrow_t& tag
729 [[nodiscard]]
bool open(
731 const std::nothrow_t& tag
754 const std::nothrow_t& tag
777 const std::nothrow_t& tag
803 const std::nothrow_t& tag
826 const std::nothrow_t& tag
836 const std::filesystem::path& directory,
837 std::filesystem::directory_options option,
838 tracker_t tracker = utility::make_shared_progress_tracker()
842 const std::filesystem::path& directory,
843 const std::nothrow_t& tag,
844 std::filesystem::directory_options option,
845 tracker_t tracker = utility::make_shared_progress_tracker()
850 tracker_t tracker = utility::make_shared_progress_tracker()
855 const std::nothrow_t& tag,
856 tracker_t tracker = utility::make_shared_progress_tracker()
873 const std::
string& type_separator = " -> "
887 const std::
string& type_separator = " -> ",
888 const std::
string& file_separator = "\n"
912 const std::
string& type_separator = " -> "
926 const std::
string& type_separator = " -> ",
927 const std::
string& file_separator = "\n"
949 const std::
string& separator = ", "
971 const std::
string& value_separator = ": "
985 const std::
string& value_separator = ": ",
986 const std::
string& parameter_separator = ", "
The magic class provides a C++ wrapper over the Magic Number Recognition Library.
Definition magic.hpp:31
bool is_open() const noexcept
Used for testing whether magic is open or closed.
Definition magic.cpp:1138
void set_flags(flags_mask_t flags_mask)
Set the flags of magic.
Definition magic.cpp:1184
expected_types_of_files_t identify_files(const std::filesystem::path &directory, const std::nothrow_t &tag, tracker_t tracker, std::filesystem::directory_options option=std::filesystem::directory_options::follow_directory_symlink) const noexcept
Identify the types of all files in a directory with progress tracking, noexcept version.
Definition magic.hpp:522
void set_parameters(const parameter_value_map_t ¶meters)
Set the values of the parameters of magic.
Definition magic.cpp:1224
std::size_t get_parameter(parameters parameter) const
Get the value of a parameter of magic.
Definition magic.cpp:1013
static bool check(const std::filesystem::path &database_file=default_database_file) noexcept
Check the validity of entries in the colon separated database files passed in as database_file.
Definition magic.cpp:982
std::unique_ptr< magic_private > m_impl
Definition magic.hpp:831
std::string error_message_t
String type representing an error message from file identification.
Definition magic.hpp:52
flags_container_t get_flags() const
Get the flags of magic.
Definition magic.cpp:1001
utility::shared_progress_tracker_t tracker_t
Alias for a shared pointer to a progress tracker used for monitoring file identification progress.
Definition magic.hpp:98
bool is_database_loaded() const noexcept
Used for testing whether a magic database is loaded or not.
Definition magic.cpp:1133
flags
The flags enums are used for configuring the flags of a magic.
Definition magic.hpp:105
@ raw
Definition magic.hpp:116
@ no_check_tokens
Definition magic.hpp:133
@ no_check_cdf
Definition magic.hpp:131
@ symlink
Definition magic.hpp:109
@ no_check_apptype
Definition magic.hpp:128
@ error
Definition magic.hpp:117
@ no_check_compress
Definition magic.hpp:125
@ no_check_tar
Definition magic.hpp:126
@ mime_type
Definition magic.hpp:112
@ mime_encoding
Definition magic.hpp:118
@ debug
Definition magic.hpp:108
@ no_check_elf
Definition magic.hpp:129
@ none
Definition magic.hpp:107
@ nodesc
Definition magic.hpp:124
@ compress_transp
Definition magic.hpp:122
@ apple
Definition magic.hpp:120
@ mime
Definition magic.hpp:119
@ compress
Definition magic.hpp:110
@ no_check_text
Definition magic.hpp:130
@ no_check_soft
Definition magic.hpp:127
@ no_compress_fork
Definition magic.hpp:123
@ preserve_atime
Definition magic.hpp:115
@ no_check_builtin
Definition magic.hpp:137
@ extension
Definition magic.hpp:121
@ devices
Definition magic.hpp:111
@ no_check_encoding
Definition magic.hpp:134
@ no_check_simh
Definition magic.hpp:136
@ no_check_csv
Definition magic.hpp:132
@ continue_search
Definition magic.hpp:113
@ check_database
Definition magic.hpp:114
@ no_check_json
Definition magic.hpp:135
magic() noexcept
Construct magic without opening it.
Definition magic.cpp:931
expected_types_of_files_t::value_type expected_type_of_a_file_t
Key-value pair representing a single file and its expected file type result.
Definition magic.hpp:89
void open(flags_mask_t flags_mask)
Open magic using the flags.
Definition magic.cpp:1161
std::map< std::filesystem::path, expected_file_type_t > expected_types_of_files_t
Map from file paths to expected file type results (success or error).
Definition magic.hpp:80
std::bitset< 30uz > flags_mask_t
Bitmask type representing a set of magic::flags used to configure the magic instance.
Definition magic.hpp:38
std::vector< flags > flags_container_t
Container type holding a collection of magic::flags.
Definition magic.hpp:165
std::vector< std::filesystem::path > default_file_container_t
Definition magic.hpp:833
file_type_t identify_file(const std::filesystem::path &path) const
Identify the type of a file.
Definition magic.cpp:1043
parameters
The parameters enums are used for displaying or modifying the parameters of a magic.
Definition magic.hpp:145
parameter_value_map_t::value_type parameter_value_t
Key-value pair representing a single parameter and its value.
Definition magic.hpp:179
expected_types_of_files_t identify_files(const utility::file_container auto &files, const std::nothrow_t &tag, tracker_t tracker) const noexcept
Identify the types of files with progress tracking, noexcept version.
Definition magic.hpp:609
types_of_files_t identify_files(const std::filesystem::path &directory, tracker_t tracker, std::filesystem::directory_options option=std::filesystem::directory_options::follow_directory_symlink) const
Identify the types of all files in a directory with progress tracking.
Definition magic.hpp:483
types_of_files_t::value_type type_of_a_file_t
Key-value pair representing a single file and its detected type.
Definition magic.hpp:73
void set_parameter(parameters parameter, std::size_t value)
Set the value of a parameter of magic.
Definition magic.cpp:1210
bool is_valid() const noexcept
Used for testing whether magic is valid for identifying file types or not.
Definition magic.cpp:1143
static std::string_view default_database_file
The path of the default database file.
Definition magic.hpp:184
std::map< parameters, std::size_t > parameter_value_map_t
Map from magic::parameters to their corresponding values.
Definition magic.hpp:172
std::expected< file_type_t, error_message_t > expected_file_type_t
Result type for file identification, containing either a file type or an error message.
Definition magic.hpp:59
types_of_files_t identify_directory_impl(const std::filesystem::path &directory, std::filesystem::directory_options option, tracker_t tracker=utility::make_shared_progress_tracker()) const
Definition magic.cpp:1063
std::string file_type_t
String type representing the detected type of a file.
Definition magic.hpp:45
expected_types_of_files_t identify_files(const utility::file_container auto &files, const std::nothrow_t &tag) const noexcept
Identify the types of files, noexcept version.
Definition magic.hpp:589
expected_types_of_files_t identify_files(const std::filesystem::path &directory, const std::nothrow_t &tag, 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:502
std::map< std::filesystem::path, file_type_t > types_of_files_t
Map from file paths to their detected types.
Definition magic.hpp:66
void close() noexcept
Close magic.
Definition magic.cpp:989
friend std::string to_string(flags)
Convert the magic::flags to string.
Definition magic.cpp:876
void load_database_file(const std::filesystem::path &database_file=default_database_file)
Load a magic database file.
Definition magic.cpp:1148
types_of_files_t identify_container_impl(const default_file_container_t &files, tracker_t tracker=utility::make_shared_progress_tracker()) const
Definition magic.cpp:1102
types_of_files_t identify_files(const utility::file_container auto &files, tracker_t tracker) const
Identify the types of files with progress tracking.
Definition magic.hpp:570
parameter_value_map_t get_parameters() const
Get the values of all parameters of magic.
Definition magic.cpp:1026
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:456
static std::string get_version() noexcept
Get the version of the Magic Number Recognition Library.
Definition magic.cpp:1038
static bool compile(const std::filesystem::path &database_file=default_database_file) noexcept
Compile the colon separated list of database files passed in as database_file.
Definition magic.cpp:994
types_of_files_t identify_files(const utility::file_container auto &files) const
Identify the types of files.
Definition magic.hpp:546
The file_container concept specifies the requirements of a container which can be used as a file cont...
Definition utility.hpp:81
std::shared_ptr< progress_tracker > shared_progress_tracker_t
Alias for a shared pointer to progress_tracker.
Definition progress_tracker.hpp:181