def _get_block_async(self, obj, **args): event = SilentEvent(self.object_get, obj, success=(200, 206), **args) event.start() return event
storage_client.container = 'pithos' obj = raw_input('Pick object to stream: ') destination = raw_input('Stream it where? ') obj_size = int(storage_client.get_object_info(obj)['content-length']) BLOCK_SIZE = int(storage_client.get_container_info()['x-container-block-size']) CHUNK_SIZE = 4 * BLOCK_SIZE def stream(i, output): """Stream the contents of buf[i] to output""" output.write(bufs[i]) from kamaki.clients import SilentEvent with open(destination, 'w+') as output: event = None bufs = ['', ''] for i in range(1 + (obj_size / CHUNK_SIZE)): buf_index = i % 2 start, end = CHUNK_SIZE * i, min(CHUNK_SIZE * (i + 1), obj_size) bufs[buf_index] = storage_client.download_to_string(obj, range_str='%s-%s' % (start, end)) if event and not event.is_alive(): event.join() event = SilentEvent(stream, buf_index, output) event.start()
def _put_block_async(self, data, hash): event = SilentEvent(method=self._put_block, data=data, hash=hash) event.start() return event
pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) storage_client = pithos.PithosClient(pithosURL, TOKEN) storage_client.account = identity_client.user_info['id'] storage_client.container = 'pithos' obj = raw_input('Pick object to stream: ') destination = raw_input('Stream it where? ') obj_size = int(storage_client.get_object_info(obj)['content-length']) BLOCK_SIZE = int(storage_client.get_container_info()['x-container-block-size']) CHUNK_SIZE = 4 * BLOCK_SIZE def stream(i, output): """Stream the contents of buf[i] to output""" output.write(bufs[i]) from kamaki.clients import SilentEvent with open(destination, 'w+') as output: event = None bufs = ['', ''] for i in range(1 + (obj_size / CHUNK_SIZE)): buf_index = i % 2 start, end = CHUNK_SIZE * i, min(CHUNK_SIZE * (i + 1), obj_size) bufs[buf_index] = storage_client.download_to_string( obj, range_str='%s-%s' % (start, end)) if event and not event.is_alive(): event.join() event = SilentEvent(stream, buf_index, output) event.start()