forked from Distributive-Network/PythonMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64.py
More file actions
23 lines (19 loc) · 633 Bytes
/
base64.py
File metadata and controls
23 lines (19 loc) · 633 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# @file base64.py
# @author Tom Tang <xmader@distributive.network>, Hamada Gasmallah <hamada@distributive.network>
# @date July 2023
import base64
atob = lambda b64: str(base64.standard_b64decode(b64), 'latin1')
btoa = lambda data: str(base64.standard_b64encode(bytes(data, 'latin1')), 'latin1')
# Make `atob`/`btoa` globally available
import pythonmonkey as pm
pm.eval(r"""(atob, btoa) => {
if (!globalThis.atob) {
globalThis.atob = atob;
}
if (!globalThis.btoa) {
globalThis.btoa = btoa;
}
}""")(atob, btoa)
# Module exports
exports['atob'] = atob # type: ignore
exports['btoa'] = btoa # type: ignore