Revision f546c15e tools/lib/transfer.py
b/tools/lib/transfer.py | ||
---|---|---|
65 | 65 |
|
66 | 66 |
with open(file) as fp: |
67 | 67 |
for hash in missing: |
68 |
offset = hashes.index(unhexlify(hash)) * BLOCK_SIZE
|
|
68 |
offset = hashes.index(unhexlify(hash)) * blocksize
|
|
69 | 69 |
fp.seek(offset) |
70 |
block = fp.read(BLOCK_SIZE)
|
|
70 |
block = fp.read(blocksize)
|
|
71 | 71 |
client.create_object(container, '.upload', StringIO(block)) |
72 | 72 |
|
73 | 73 |
client.create_object_by_hashmap(container, object, map) |
74 |
|
|
75 |
def download(client, container, object, file): |
|
76 |
|
|
77 |
meta = client.retrieve_container_metadata(container) |
|
78 |
blocksize = int(meta['x-container-block-size']) |
|
79 |
blockhash = meta['x-container-block-hash'] |
|
80 |
|
|
81 |
if os.path.isfile(file): |
|
82 |
size = os.path.getsize(file) |
|
83 |
hashes = HashMap(blocksize, blockhash) |
|
84 |
hashes.load(file) |
|
85 |
else: |
|
86 |
size = 0 |
|
87 |
hashes = [] |
|
88 |
|
|
89 |
map = client.retrieve_object_hashmap(container, object) |
|
90 |
|
|
91 |
with open(file, 'a') as fp: |
|
92 |
for i, h in enumerate(map): |
|
93 |
if i < len(hashes) and h == hashes[i]: |
|
94 |
continue |
|
95 |
start = i * blocksize |
|
96 |
end = '' if i == len(map) - 1 else (i + 1) * blocksize |
|
97 |
data = client.retrieve_object(container, object, range='bytes=%s-%s' % (start, end)) |
|
98 |
fp.seek(start) |
|
99 |
fp.write(data) |
Also available in: Unified diff