Commit 810d80b8 authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Add an optional size argument in create_object

parent 215321e9
......@@ -57,7 +57,8 @@ class PithosClient(StorageClient):
success=202)
assert r.text.strip() == hash, 'Local hash does not match server'
def create_object(self, object, f, hash_cb=None, upload_cb=None):
def create_object(self, object, f, size=None, hash_cb=None,
upload_cb=None):
"""Create an object by uploading only the missing blocks
hash_cb is a generator function taking the total number of blocks to
......@@ -73,7 +74,7 @@ class PithosClient(StorageClient):
blocksize = int(meta['block-size'])
blockhash = meta['block-hash']
file_size = os.fstat(f.fileno()).st_size
file_size = size if size is not None else os.fstat(f.fileno()).st_size
nblocks = 1 + (file_size - 1) // blocksize
hashes = OrderedDict()
......
......@@ -74,11 +74,12 @@ class StorageClient(Client):
return reply
def create_object(self, object, f, hash_cb=None, upload_cb=None):
def create_object(self, object, f, size=None, hash_cb=None,
upload_cb=None):
# This is a naive implementation, it loads the whole file in memory
self.assert_container()
path = '/%s/%s/%s' % (self.account, self.container, object)
data = f.read()
data = f.read(size) if size is not None else f.read()
self.put(path, data=data, success=201)
def get_object(self, object):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment