FileAsCArray is a command-line tool designed to convert any file into a C-style array, making it easier for developers to embed binary data directly into C or C++ source code.
python file_as_c_array.py <file_path> [-o <output_path>]
-
<file_path>: Path to the binary file to be converted.
-
-o, --output (optional): Output file to write the C array. If not specified, the output will be printed to the console.
python file_as_c_array.py ./path/to/github-logo.png
const uint8_t github-logo[460] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,
0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff,
...
0xca, 0x06, 0x7e, 0x88, 0xcd, 0x66, 0xfe, 0x5f,
0xab, 0xd8, 0x01, 0x2a, 0x46, 0x61, 0x15, 0xcc,
0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
0xae, 0x42, 0x60, 0x82
};
const uint64_t github-logo_len = 460;
