MCPcopy Index your code
hub / github.com/TaskingAI/TaskingAI / encode_text_to_base64

Function encode_text_to_base64

backend/tkhelper/utils/base_64.py:6–26  ·  view source on GitHub ↗

Encodes a given input text string to a Base64 encoded string. :param input_string: str - The string to be encoded. :param exclude_padding: bool - Whether to exclude the padding characters '=' from the output. :return: str - The Base64 encoded string.

(input_string, exclude_padding=False)

Source from the content-addressed store, hash-verified

4
5
6def encode_text_to_base64(input_string, exclude_padding=False):
7 """
8 Encodes a given input text string to a Base64 encoded string.
9
10 :param input_string: str - The string to be encoded.
11 :param exclude_padding: bool - Whether to exclude the padding characters '=' from the output.
12 :return: str - The Base64 encoded string.
13 """
14
15 # Convert the input string to bytes
16 input_bytes = input_string.encode("utf-8")
17
18 # Encode these bytes and then decode the result to get a string
19 base64_bytes = base64.b64encode(input_bytes)
20 base64_string = base64_bytes.decode("utf-8")
21
22 # Optionally exclude the padding characters
23 if exclude_padding:
24 base64_string = base64_string.rstrip("=")
25
26 return base64_string
27
28
29def decode_base64_to_text(base64_string):

Callers 1

Calls 2

encodeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected