-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbp_to_json_bin.py
More file actions
31 lines (24 loc) · 798 Bytes
/
bp_to_json_bin.py
File metadata and controls
31 lines (24 loc) · 798 Bytes
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
import base64
import zlib
import io
import sys
import os
def error(*args):
print(*args, file=sys.stderr, flush=True)
################################################################
#
# main
if __name__ == "__main__":
#sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding="utf-8")
exchange_str = sys.stdin.read().strip()
version_byte = exchange_str[0]
if version_byte == "0":
bin_data = zlib.decompress(base64.b64decode(exchange_str[1:]))
#sys.stdout.buffer.write(bin_data)
with os.fdopen(sys.stdout.fileno(), "wb", closefd=False) as stdout:
stdout.write(bin_data)
stdout.flush()
# print("bin_data = ", type(bin_data))
else:
error("Unsupported version: {0}".format(version_byte))
exit(2)