|
Libmagicxx v10.0.3
A modern C++23 wrapper for libmagic — the library that powers the Unix file command.
|
Comprehensive examples demonstrating libmagicxx usage. More...

Functions | |
| void | ExampleBasicIdentify () |
| Example 1: Basic file identification with exception handling. | |
| void | ExampleNoexceptIdentify () |
| Example 2: File identification using the noexcept API. | |
| void | ExampleIdentifyDirectory () |
| Example 3: Batch identification of files in a directory. | |
| void | ExampleCustomFlagsParameters () |
| Example 4: Configuring flags and parameters. | |
| void | ExampleCheckAndCompile () |
| Example 5: Database validation and compilation. | |
| void | ExampleProgressTracking () |
| Example 6: Progress tracking for batch operations. | |
| void | ExampleContainerIdentify () |
| Example 7: Identify specific files from a container. | |
| void | ExampleLifecycleManagement () |
| Example 8: Manual lifecycle and state queries. | |
| void | ExampleVersionAndAllParameters () |
| Example 9: Get version and all parameters. | |
| auto | main () -> int |
| Main entry point for the examples program. | |
Comprehensive examples demonstrating libmagicxx usage.
This file contains practical examples showing how to use libmagicxx — a modern C++23 wrapper for libmagic, the library that powers the Unix file command. Each example demonstrates a different aspect of the library's functionality.
| Example | Description |
|---|---|
| ExampleBasicIdentify() | Basic file identification with exception handling |
| ExampleNoexceptIdentify() | File identification using noexcept API |
| ExampleIdentifyDirectory() | Batch identification of files in a directory |
| ExampleCustomFlagsParameters() | Configuring flags and parameters |
| ExampleCheckAndCompile() | Database validation and compilation |
| ExampleProgressTracking() | Progress tracking for batch operations |
| ExampleContainerIdentify() | Identify specific files from a container |
| ExampleLifecycleManagement() | Manual lifecycle and state queries |
| ExampleVersionAndAllParameters() | Get version and all parameters |
Build the examples using CMake with the examples preset:
After building, run the examples executable:
| void ExampleBasicIdentify | ( | ) |
Example 1: Basic file identification with exception handling.
This example demonstrates the most common usage pattern:
| void ExampleCheckAndCompile | ( | ) |
Example 5: Database validation and compilation.
This example demonstrates database management:
These are static methods that don't require a Magic instance. They operate on the default database file unless a path is specified.
| void ExampleContainerIdentify | ( | ) |
Example 7: Identify specific files from a container.
This example demonstrates batch file identification:
Use this pattern when you have a known list of files rather than scanning a directory.
| void ExampleCustomFlagsParameters | ( | ) |
Example 4: Configuring flags and parameters.
This example demonstrates advanced configuration:
| void ExampleIdentifyDirectory | ( | ) |
Example 3: Batch identification of files in a directory.
This example demonstrates directory scanning:
The IdentifyFiles() method recursively scans the directory and returns a map from file paths to their identified types.
| void ExampleLifecycleManagement | ( | ) |
Example 8: Manual lifecycle and state queries.
This example demonstrates lifecycle management:
| void ExampleNoexceptIdentify | ( | ) |
Example 2: File identification using the noexcept API.
This example demonstrates the non-throwing API pattern:
The noexcept API is useful when:
| void ExampleProgressTracking | ( | ) |
Example 6: Progress tracking for batch operations.
This example demonstrates progress monitoring:
Progress tracking is useful for:
| void ExampleVersionAndAllParameters | ( | ) |
Example 9: Get version and all parameters.
This example demonstrates:
| auto main | ( | ) | -> int |
Main entry point for the examples program.
Runs all example functions sequentially, demonstrating various features of the libmagicxx library.