def cmd_b64(f, do_decode):
    """
    Encodes or decode data in base64, just like the command base64.

    \b
    $ echo awesome | habu.b64
    YXdlc29tZQo=

    \b
    $ echo YXdlc29tZQo= | habu.b64 -d
    awesome
    """

    data = f.read()

    if not data:
        print("Empty file or string!")
        return 1

    if do_decode:
        os.write(sys.stdout.fileno(), base64.b64decode(data))
    else:
        os.write(sys.stdout.fileno(), base64.b64encode(data))
Encodes or decode data in base64, just like the command base64.

    \b
    $ echo awesome | habu.b64
    YXdlc29tZQo=

    \b
    $ echo YXdlc29tZQo= | habu.b64 -d
    awesome