aboutsummaryrefslogtreecommitdiff
path: root/tools/file2json.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-08-02 11:01:20 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-08-02 11:01:20 -0700
commit44055881b14b322139b6c9c82d718a807f7928ea (patch)
tree5f73dd3cbc5aa6538e7b535d4730593e52401b77 /tools/file2json.py
parent0c4cea3a11d4fbd53d318bc6f258946ecafe1948 (diff)
file2json utility
Diffstat (limited to 'tools/file2json.py')
-rw-r--r--tools/file2json.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/file2json.py b/tools/file2json.py
new file mode 100644
index 00000000..3ee7da10
--- /dev/null
+++ b/tools/file2json.py
@@ -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 + ';'
+