Add an optional size argument in create_object
authorGiorgos Verigakis <verigak@gmail.com>
Mon, 19 Mar 2012 16:33:54 +0000 (18:33 +0200)
committerGiorgos Verigakis <verigak@gmail.com>
Wed, 9 May 2012 10:18:46 +0000 (13:18 +0300)
kamaki/clients/pithos.py
kamaki/clients/storage.py

index d56e110..e12f0ea 100644 (file)
@@ -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()
         
index 5b6a2d9..ce53cd2 100644 (file)
@@ -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):