1234567891011121314151617181920 |
-
- import os
-
- # https://stackoverflow.com/questions/49449430/python-bytes-to-c-array-like-xxd-program/49450004
- def bytes_to_c_arr(data, lowercase=True):
- return [format(b, '#04x' if lowercase else '#04X') for b in data]
-
- src = 'include/http'
- out = 'include'
-
- for f in os.listdir(src):
- with open(f'{src}/{f}', 'rb') as f_in:
- with open(f'{out}/{f}.h', 'wb') as f_out:
- buf = 'const char {}[] = {{{}}};'.format(
- f.replace('.', '_'),
- ', '.join(bytes_to_c_arr(f_in.read()))
- )
- f_out.write(buf.encode(encoding='ascii'))
-
|