Magic construction methods.
More...
Magic construction methods.
Constructors for creating Magic instances in various initial states.
◆ Magic() [1/5]
| Recognition::Magic::Magic |
( |
| ) |
|
|
noexcept |
Default constructor. Creates an unopened Magic instance.
The instance is not valid for file identification until Open() and LoadDatabaseFile() are called.
Magic() noexcept
Default constructor. Creates an unopened Magic instance.
Definition magic.cpp:2421
void LoadDatabaseFile(const std::filesystem::path &database_file=DEFAULT_DATABASE_FILE)
Load a magic database file.
Definition magic.cpp:2638
@ Mime
Definition magic.hpp:328
void Open(FlagsMaskT flags_mask)
Open Magic with specified flags.
Definition magic.cpp:2651
- See also
- Open()
-
LoadDatabaseFile()
-
IsValid()
- Since
- 10.0.0
◆ Magic() [2/5]
Construct and initialize Magic with a container of flags.
Alternative constructor accepting a container of individual flags instead of a bitmask. Useful when flags are determined at runtime.
- Parameters
-
| [in] | flags_container | Vector or other container of Flags values. |
| [in] | database_file | Path to magic database file (default: DEFAULT_DATABASE_FILE). |
- Exceptions
-
| MagicOpenError | If opening the Magic instance fails. |
| EmptyPath | If database_file path is empty. |
| PathDoesNotExist | If database_file does not exist. |
| PathIsNotRegularFile | If database_file is not a regular file. |
| MagicLoadDatabaseFileError | If loading the database fails. |
A modern C++23 wrapper for libmagic — the library that powers the Unix file command.
Definition magic.hpp:216
@ Compress
Definition magic.hpp:319
- Note
- The ".mgc" extension is automatically appended to the database path if needed.
- See also
- FlagsContainerT
- Since
- 10.0.0
◆ Magic() [3/5]
Construct and initialize Magic with a container of flags (noexcept version).
Non-throwing variant that silently fails if initialization errors occur. Check IsValid() after construction to verify success.
- Parameters
-
| [in] | flags_container | Vector or other container of Flags values. |
| [in] | tag | Pass std::nothrow to select this overload. |
| [in] | database_file | Path to magic database file (default: DEFAULT_DATABASE_FILE). |
- Note
- The ".mgc" extension is automatically appended to the database path if needed.
- See also
- IsValid()
- Since
- 10.0.0
◆ Magic() [4/5]
Construct and initialize Magic with flags and database.
This constructor opens Magic with the specified flags and loads the magic database file in a single step. On success, the instance is immediately ready for file identification.
- Parameters
-
| [in] | flags_mask | Configuration flags (use Flags enum values combined with |). |
| [in] | database_file | Path to magic database file (default: DEFAULT_DATABASE_FILE). |
- Exceptions
-
| MagicOpenError | If opening the Magic instance fails. |
| EmptyPath | If database_file path is empty. |
| PathDoesNotExist | If database_file does not exist. |
| PathIsNotRegularFile | If database_file is not a regular file. |
| MagicLoadDatabaseFileError | If loading the database fails. |
- Note
- The ".mgc" extension is automatically appended to the database path if needed.
- See also
- LoadDatabaseFile()
- Since
- 10.0.0
◆ Magic() [5/5]
Construct and initialize Magic with flags and database (noexcept version).
Non-throwing variant that silently fails if initialization errors occur. Check IsValid() after construction to verify success.
- Parameters
-
| [in] | flags_mask | Configuration flags (use Flags enum values combined with |). |
| [in] | tag | Pass std::nothrow to select this overload. |
| [in] | database_file | Path to magic database file (default: DEFAULT_DATABASE_FILE). |
}
bool IsValid() const noexcept
Check if the Magic instance is valid for file identification.
Definition magic.cpp:2633
- Note
- The ".mgc" extension is automatically appended to the database path if needed.
- See also
- IsValid()
- Since
- 10.0.0