Main header file for the cpp-filetype library. More...
#include <array>#include <cstdint>#include <string>#include <string_view>#include <vector>#include "types.hpp"Go to the source code of this file.
Functions | |
| bool | filetype::is_valid_buffer (const std::vector< uint8_t > &bytes, size_t min_size=8) |
| Validate if a buffer has sufficient data for type detection. | |
| bool | filetype::match_magic (const std::vector< uint8_t > &bytes, const uint8_t *magic, size_t magic_size, size_t offset=0) |
| Compare bytes with a magic number pattern. | |
| template<size_t N> | |
| bool | filetype::match_magic (const std::vector< uint8_t > &bytes, const std::array< uint8_t, N > &magic, size_t offset=0) |
| Template version of match_magic for std::array magic numbers. | |
| bool | filetype::is_type (const std::vector< uint8_t > &bytes, const uint8_t *magic, size_t magic_size, size_t offset=0) |
| Check if the file type matches a specific format. | |
| template<size_t N> | |
| bool | filetype::is_type (const std::vector< uint8_t > &bytes, const std::array< uint8_t, N > &magic, size_t offset=0) |
| Template version of is_type for std::array magic numbers. | |
| const Type * | filetype::match (const std::vector< uint8_t > &bytes) |
| Detect file type from a byte buffer. | |
| const Type * | filetype::match_file (std::string_view filepath, size_t max_read_size=8192) |
| Detect file type from a file path. | |
| bool | filetype::is (const std::vector< uint8_t > &bytes, const Type &type) |
| Check if file has a specific type. | |
| bool | filetype::is_image (const std::vector< uint8_t > &bytes) |
| Check if file is an image. | |
| bool | filetype::is_document (const std::vector< uint8_t > &bytes) |
| Check if file is a document. | |
| bool | filetype::is_archive (const std::vector< uint8_t > &bytes) |
| Check if file is an archive. | |
| bool | filetype::is_audio (const std::vector< uint8_t > &bytes) |
| Check if file is an audio file. | |
| bool | filetype::is_video (const std::vector< uint8_t > &bytes) |
| Check if file is a video file. | |
| const Type * | filetype::matcher::match_image (const std::vector< uint8_t > &bytes) |
| Match image file types. | |
| const Type * | filetype::matcher::match_document (const std::vector< uint8_t > &bytes) |
| Match document file types. | |
| const Type * | filetype::matcher::match_archive (const std::vector< uint8_t > &bytes) |
| Match archive file types. | |
| const Type * | filetype::matcher::match_audio (const std::vector< uint8_t > &bytes) |
| Match audio file types. | |
| const Type * | filetype::matcher::match_video (const std::vector< uint8_t > &bytes) |
| Match video file types. | |
Main header file for the cpp-filetype library.
This library provides functionality to detect file types based on their magic numbers. Supported file types include images, documents, archives, audio, and video formats.
| bool filetype::is | ( | const std::vector< uint8_t > & | bytes, |
| const Type & | type ) |
Check if file has a specific type.
| bytes | Buffer containing file data. |
| type | Type to check against. |
| bool filetype::is_archive | ( | const std::vector< uint8_t > & | bytes | ) |
Check if file is an archive.
| bytes | Buffer containing file data. |
| bool filetype::is_audio | ( | const std::vector< uint8_t > & | bytes | ) |
Check if file is an audio file.
| bytes | Buffer containing file data. |
| bool filetype::is_document | ( | const std::vector< uint8_t > & | bytes | ) |
Check if file is a document.
| bytes | Buffer containing file data. |
| bool filetype::is_image | ( | const std::vector< uint8_t > & | bytes | ) |
Check if file is an image.
| bytes | Buffer containing file data. |
| bool filetype::is_type | ( | const std::vector< uint8_t > & | bytes, |
| const std::array< uint8_t, N > & | magic, | ||
| size_t | offset = 0 ) |
Template version of is_type for std::array magic numbers.
| N | Size of the magic number array. |
| bytes | Buffer containing file data. |
| magic | Array containing the magic number sequence. |
| offset | Offset where the magic number should appear (default: 0). |
| bool filetype::is_type | ( | const std::vector< uint8_t > & | bytes, |
| const uint8_t * | magic, | ||
| size_t | magic_size, | ||
| size_t | offset = 0 ) |
Check if the file type matches a specific format.
| bytes | Buffer containing file data. |
| magic | Magic number sequence to match. |
| magic_size | Size of the magic number sequence. |
| offset | Offset where the magic number should appear (default: 0). |
| bool filetype::is_valid_buffer | ( | const std::vector< uint8_t > & | bytes, |
| size_t | min_size = 8 ) |
Validate if a buffer has sufficient data for type detection.
| bytes | Input buffer to validate. |
| min_size | Minimum required size for the buffer (default: 8 bytes). |
| bool filetype::is_video | ( | const std::vector< uint8_t > & | bytes | ) |
Check if file is a video file.
| bytes | Buffer containing file data. |
| const Type * filetype::match | ( | const std::vector< uint8_t > & | bytes | ) |
Detect file type from a byte buffer.
This function attempts to detect the file type by comparing the buffer's contents with known magic numbers of various file formats.
| bytes | Buffer containing the file data to analyze. |
| const Type * filetype::matcher::match_archive | ( | const std::vector< uint8_t > & | bytes | ) |
Match archive file types.
| bytes | Buffer containing file data. |
| const Type * filetype::matcher::match_audio | ( | const std::vector< uint8_t > & | bytes | ) |
Match audio file types.
| bytes | Buffer containing file data. |
| const Type * filetype::matcher::match_document | ( | const std::vector< uint8_t > & | bytes | ) |
Match document file types.
| bytes | Buffer containing file data. |
| const Type * filetype::match_file | ( | std::string_view | filepath, |
| size_t | max_read_size = 8192 ) |
Detect file type from a file path.
This function reads the beginning of the file and attempts to detect its type by comparing with known magic numbers.
| filepath | Path to the file to analyze. |
| max_read_size | Maximum number of bytes to read from the file (default: 8192). |
| const Type * filetype::matcher::match_image | ( | const std::vector< uint8_t > & | bytes | ) |
Match image file types.
| bytes | Buffer containing file data. |
| bool filetype::match_magic | ( | const std::vector< uint8_t > & | bytes, |
| const std::array< uint8_t, N > & | magic, | ||
| size_t | offset = 0 ) |
Template version of match_magic for std::array magic numbers.
| N | Size of the magic number array. |
| bytes | Buffer containing file data. |
| magic | Array containing the magic number sequence. |
| offset | Offset in bytes where to start matching (default: 0). |
| bool filetype::match_magic | ( | const std::vector< uint8_t > & | bytes, |
| const uint8_t * | magic, | ||
| size_t | magic_size, | ||
| size_t | offset = 0 ) |
Compare bytes with a magic number pattern.
| bytes | Buffer containing file data. |
| magic | Pointer to magic number sequence. |
| magic_size | Length of the magic number sequence. |
| offset | Offset in bytes where to start matching (default: 0). |
| const Type * filetype::matcher::match_video | ( | const std::vector< uint8_t > & | bytes | ) |
Match video file types.
| bytes | Buffer containing file data. |