2
Converts a binary file into JSON.
4
This lets you transform a binary file into something you can
5
easily bundle inside a web page.
7
Usage: file2json.py FILENAME VARNAME
9
FILENAME - the binary file
10
VARNAME - the variable to store it in (the output will be VARNAME = [...])
15
data = open(sys.argv[1], 'r').read()
16
sdata = map(lambda x: str(ord(x)) + ',', data)
17
sdata[-1] = sdata[-1].replace(',', '')
24
json = '[' + ''.join(lined) + ']'
29
print 'var ' + sys.argv[2] + '=' + json + ';'
32
or (but this fails, we get a string at runtime?)
34
data = open(sys.argv[1], 'r').read()
37
for i in range(len(data)):
38
last = i == len(data)-1
43
if counter % 1005 == 0 and not last:
45
elif not last: print ',',