Created
April 12, 2025 22:02
-
-
Save saschazepter/bbf2c1ce905ef54a708130834bfb8909 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/env python3 | |
# | |
# Carlos Albornoz <[email protected]> | |
# | |
RELATIVE = 1 | |
BLOCK_SIZE = 2**20 | |
import tarfile | |
import os | |
import sys | |
(xva_filename, ref, blocks, output) = tuple(sys.argv[1:]) | |
blocks = int(blocks) | |
xva = tarfile.open(xva_filename) | |
def get_block(ref, n): | |
try: | |
b = xva.extractfile(f"{ref}/{n:08d}").read() | |
return b | |
except KeyError: | |
return None | |
with open(output, 'wb') as fd: | |
for n in range(0, blocks + 1): | |
if n % 123 == 0: | |
print(f'\r{n}', end='', flush=True) | |
block = get_block(ref, n) | |
if block is not None: | |
fd.write(block) | |
else: | |
fd.seek(BLOCK_SIZE, RELATIVE) | |
print('\rDone. ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment