Skip to content

Instantly share code, notes, and snippets.

@C47D
Last active February 16, 2019 18:41
Show Gist options
  • Save C47D/6b157424db5417b0cc2131c536ba32c0 to your computer and use it in GitHub Desktop.
Save C47D/6b157424db5417b0cc2131c536ba32c0 to your computer and use it in GitHub Desktop.
Test script to convert from a Python ByteArray to a C array
#!/usr/bin/python3
oggDataArray = []
ogg_decoded_file = 'ogg_decoded'
output_file = 'test.c'
print('Opening {}.'.format(ogg_decoded_file))
with open(ogg_decoded_file, 'rb') as f:
byte = f.read(1)
while byte:
oggDataArray.append(byte)
byte = f.read(1)
print('Dumping data to {}.'.format(output_file))
with open(output_file, 'w+') as f:
f.write('const uint8_t array[] = {\n')
f.write(''.join(['0x%02X, ' % ord(x) for x in oggDataArray]).strip())
f.write('\n}')
print('Done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment