diff --git a/cq-cli.py b/cq-cli.py index ba53197..c76e20c 100755 --- a/cq-cli.py +++ b/cq-cli.py @@ -388,8 +388,14 @@ def main(): if outfile == None: print(converted) else: - with open(outfile, 'w') as file: - file.write(converted) + if isinstance(converted, str): + with open(outfile, 'w') as file: + file.write(converted) + elif isinstance(converted, (bytes, bytearray)): + with open(outfile, 'wb') as file: + file.write(converted) + else: + raise TypeError("Expected converted output to be str, bytes, or bytearray. Got '%s'" % type(converted).__name__) except Exception: out_tb = traceback.format_exc()