Python Forum
best way to copy a big binary file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
best way to copy a big binary file
#13
Skaperen Wrote:i also want to be able to output a progress indicator
Use tqdm A Fast, Extensible Progress Bar for Python and CLI.
If i write a test,also rewrite previous code to use for loop bye using functools.partial.
from functools import partial
from tqdm import tqdm
import os

def file_copy(file_name, path_out, buffer_size=1024000):
    with tqdm(total=os.path.getsize(file_name), unit='B', unit_scale=True) as pbar:
        with open(file_name, 'rb') as fsrc,open(f'{path_out}/{file_name}', 'wb') as fdst:
                for byte in tqdm(iter(partial(fsrc.read, buffer_size), b'')):
                    fdst.write(byte)
                    pbar.update(len(byte))

if __name__ == '__main__':
    path_out = 'C:/code/out'
    file_name = '2.1GB.rar'
    file_copy(file_name, path_out)
Okay speed(6-sec for 2.1GB) with this buffer size as i have set to default.
[Image: DA52D3.png]
Reply


Messages In This Thread
best way to copy a big binary file - by Skaperen - Aug-26-2019, 07:17 PM
RE: best way to copy a big binary file - by Larz60+ - Aug-26-2019, 07:36 PM
RE: best way to copy a big binary file - by wavic - Aug-29-2019, 10:38 AM
RE: best way to copy a big binary file - by Larz60+ - Sep-02-2019, 04:11 AM
RE: best way to copy a big binary file - by Larz60+ - Sep-02-2019, 11:58 PM
RE: best way to copy a big binary file - by Larz60+ - Sep-05-2019, 03:43 AM
RE: best way to copy a big binary file - by snippsat - Sep-05-2019, 03:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how would you copy a file? Skaperen 17 5,196 Oct-04-2019, 07:15 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020