From 188f23b9327c0f21a3f3dc71e3686f68bf486a50 Mon Sep 17 00:00:00 2001 From: Giorgos Verigakis Date: Mon, 19 Mar 2012 18:33:54 +0200 Subject: [PATCH] Add an optional size argument in create_object --- kamaki/clients/pithos.py | 5 +++-- kamaki/clients/storage.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kamaki/clients/pithos.py b/kamaki/clients/pithos.py index d56e110..e12f0ea 100644 --- a/kamaki/clients/pithos.py +++ b/kamaki/clients/pithos.py @@ -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() diff --git a/kamaki/clients/storage.py b/kamaki/clients/storage.py index 5b6a2d9..ce53cd2 100644 --- a/kamaki/clients/storage.py +++ b/kamaki/clients/storage.py @@ -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): -- 1.7.10.4