This commit is contained in:
Alon Zakai 2011-08-02 11:01:20 -07:00
Родитель 0c4cea3a11
Коммит 44055881b1
1 изменённых файлов: 20 добавлений и 0 удалений

20
tools/file2json.py Normal file
Просмотреть файл

@ -0,0 +1,20 @@
'''
Converts a binary file into JSON.
This lets you transform a binary file into something you can
easily bundle inside a web page.
Usage: file2json.py FILENAME VARNAME
FILENAME - the binary file
VARNAME - the variable to store it in (the output will be VARNAME = [...])
'''
import os, sys
data = open(sys.argv[1], 'r').read()
sdata = map(lambda x: str(ord(x)), data)
json = '[' + ','.join(sdata) + ']'
print 'var ' + sys.argv[2] + '=' + json + ';'