Skip to content

Instantly share code, notes, and snippets.

@swanav
Created March 5, 2022 10:37
Show Gist options
  • Save swanav/5c824dc3b32fa97379c216e99e73a3e2 to your computer and use it in GitHub Desktop.
Save swanav/5c824dc3b32fa97379c216e99e73a3e2 to your computer and use it in GitHub Desktop.
Create a base64 string for a file
import argparse
import base64
def main(args):
file_content = None
with open(args.input, 'rb') as f:
file_content = f.read()
b64_content = base64.b64encode(file_content)
with open(args.output, 'w') as f:
f.write(b64_content.decode('utf-8'))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', required=True, help='Input file')
parser.add_argument('-o', '--output', required=True, help='Output file')
main(parser.parse_args())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment