Encode binary

This commit is contained in:
wqy
2023-10-21 10:36:16 +08:00
parent c925e2f1fa
commit 94597a2125
2 changed files with 11 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ import platform
import os
import sys
import json
import base64
from typing import Any
sys.path.append("..")
from api import project
@@ -232,10 +233,13 @@ def dump_report(path: str) -> str:
def dump_output_binary(path: str) -> str:
return open(path, 'rb').read()
with open(path, 'rb') as f:
data = f.read()
bast64_data = base64.b64encode(data)
return str(bast64_data, 'utf-8')
def run_project(name: str) -> str:
def run_project(name: str, readable_output: bool = False) -> str:
if not project.have_project(name):
raise Exception(f'Not found project [{name}]')
@@ -258,8 +262,10 @@ def run_project(name: str) -> str:
data['simulation_result'] = 'failed'
else:
data['simulation_result'] = 'successful'
# data |= _dump_output(opt)
data['output'] = dump_output_binary(opt)
if readable_output:
data |= _dump_output(opt)
else:
data['output'] = dump_output_binary(opt)
data['report'] = dump_report(rpt)