Onionr/src/onionrutils/bytesconverter.py

17 lines
393 B
Python
Raw Normal View History

2020-03-16 07:55:36 +00:00
def str_to_bytes(data: str) -> bytes:
'''Convert a string to bytes with .encode(), utf8'''
try:
2019-06-26 20:13:36 +00:00
data = data.encode('UTF-8')
except AttributeError:
pass
return data
2020-03-16 07:55:36 +00:00
def bytes_to_str(data: bytes) -> str:
"""Convert bytes to strings with .decode(), utf8"""
try:
2019-06-26 20:13:36 +00:00
data = data.decode('UTF-8')
except AttributeError:
pass
2019-08-09 20:41:27 +00:00
return data