bpo-32713: Fix tarfile.itn for large/negative float values. (GH-5434)
[python-delta-tar] / file_crypt.py
index 04d58c5..dd74bf5 100755 (executable)
@@ -30,7 +30,7 @@ def initialize_encryption (mode, password=None, key=None, nacl=None):
         return crypto.Decrypt (password=password, key=key)
 
 
-def main(do_encrypt, in_file, out_file, password, comptype='gz', enctype='aes',
+def main(do_encrypt, in_file, out_file, password, comptype='gz',
          bufsize=tarfile.RECORDSIZE, encoding='UTF-8'):
     """ Main function, called when running file as script
 
@@ -43,7 +43,7 @@ def main(do_encrypt, in_file, out_file, password, comptype='gz', enctype='aes',
     try:
         # open file to read
         if do_encrypt:
-            read_handle = open(in_file, 'rt')
+            read_handle = open(in_file, 'rb')
         else:
             decryptor = initialize_encryption (CRYPTO_MODE_DECRYPT,
                                                password=password)
@@ -60,17 +60,20 @@ def main(do_encrypt, in_file, out_file, password, comptype='gz', enctype='aes',
                                            comptype=comptype, bufsize=bufsize,
                                            fileobj=None, encryption=encryptor)
         else:
-            write_handle = open(out_file, 'wt')
+            write_handle = open(out_file, 'wb')
         return_code = 1
 
         # convert
+        total = 0
         while True:
             buf = read_handle.read(bufsize)
+            total += len(buf)
             print('.', end='')
             if do_encrypt:
-                write_handle.write(buf.encode(encoding, errors='strict'))
+                write_handle.write(buf)
             else:
-                write_handle.write(buf.decode(encoding, errors='replace'))
+                # write_handle.write(buf.decode(encoding, errors='replace'))
+                write_handle.write(buf)
             if len(buf) < bufsize:
                 if do_encrypt:
                     print('successfully encrypted {} into {}'