Created
November 11, 2025 22:23
-
-
Save nicolas17/6d3db01948e3ad02cd12a9686b3b4c7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| # Copyright (c) 2024 Nicolás Alvarez | |
| # SPDX-License-Identifier: MIT | |
| # Usage: fastdd.py <source> <dest> | |
| # | |
| # Will copy blocks from source to destination, | |
| # unless the destination block already has the correct content. | |
| import sys | |
| import os | |
| from tqdm import tqdm | |
| BLOCK_SIZE=1024*4096 | |
| data_written = 0 | |
| data_saved = 0 | |
| size = os.path.getsize(sys.argv[1]) | |
| #size = 7969177600 | |
| pbar = tqdm(total=size, unit="B", unit_scale=True) | |
| pos = 0 | |
| with open(sys.argv[1], "rb") as inf, open(sys.argv[2], "r+b") as outf, pbar: | |
| while True: | |
| outf.seek(pos) | |
| block = inf.read(BLOCK_SIZE) | |
| if len(block) == 0: break | |
| if outf.read(BLOCK_SIZE) != block: | |
| outf.seek(pos) | |
| outf.write(block) | |
| data_written += len(block) | |
| else: | |
| data_saved += len(block) | |
| pbar.update(len(block)) | |
| pos += len(block) | |
| print(f"Wrote {data_written/1024/1024:.1f}MB") | |
| print(f"Avoided writing {data_saved/1024/1024:.1f}MB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment