Skip to content

Commit

Permalink
write base64-decoded binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Jan 6, 2024
1 parent ef8218f commit 2da9c8a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions shinylive/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,16 @@ def decode(url: str, dir: Optional[str] = None, json: bool = False) -> None:
out_dir = Path(dir)
out_dir.mkdir(parents=True, exist_ok=True)
for file in bundle:
with open(out_dir / file["name"], "w") as f_out:
f_out.write(
file["content"].encode("utf-8", errors="ignore").decode("utf-8")
)
if "type" in file and file["type"] == "binary":
import base64

with open(out_dir / file["name"], "wb") as f_out:
f_out.write(base64.b64decode(file["content"]))
else:
with open(out_dir / file["name"], "w") as f_out:
f_out.write(
file["content"].encode("utf-8", errors="ignore").decode("utf-8")
)
else:
print("")
for file in bundle:
Expand Down

0 comments on commit 2da9c8a

Please sign in to comment.