FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
emscripten/tools/file2json.py at universal-python · JavaScriptIOT/emscripten · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
JavaScriptIOT
/
emscripten
Public
forked from
emscripten-core/emscripten
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
emscripten
/
tools
/
file2json.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (39 loc) · 1000 Bytes
Breadcrumbs
emscripten
/
tools
/
file2json.py
Copy path
File metadata and controls
49 lines (39 loc) · 1000 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
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
)
sdata
[
-
1
]
=
sdata
[
-
1
].
replace
(
','
,
''
)
lined
=
[]
while
len
(
sdata
)
>
0
:
lined
+=
sdata
[:
30
]
sdata
=
sdata
[
30
:]
if
len
(
sdata
)
>
0
:
lined
+=
[
'
\n
'
]
json
=
'['
+
''
.
join
(
lined
)
+
']'
if
len
(
sys
.
argv
)
<
3
:
print
json
else
:
print
'var '
+
sys
.
argv
[
2
]
+
'='
+
json
+
';'
'''
or (but this fails, we get a string at runtime?)
data = open(sys.argv[1], 'r').read()
counter = 0
print '[',
for i in range(len(data)):
last = i == len(data)-1
print ord(data[i]),
counter += 1
if counter % 20 == 0:
print
if counter % 1005 == 0 and not last:
print '] + [',
elif not last: print ',',
print ']'
'''
Back
|
FazBrowse Home
|
New Git URL