示例#1
0
 def put(self, fh):
     """
     Store some binary data in a Resource stored in Cassandra
     """
     if not (hasattr(fh, 'read')):
         data = fh
         do = DataObject.create(data, compressed=radon.cfg.compress_do)
     else:
         chunk = fh.read(radon.cfg.chunk_size)
         do = DataObject.create(chunk, compressed=radon.cfg.compress_do)
         seq_num = 1
         while True:
             chunk = fh.read(radon.cfg.chunk_size)
             if not chunk:
                 break
             DataObject.append_chunk(do.uuid, seq_num, chunk,
                                     radon.cfg.compress_do)
             do.size += len(chunk)
             seq_num += 1
     self.obj = do
     self.obj_id = do.uuid
     self.url = do.get_url()
     self.node.object_url = self.url
     self.node.save()
     return do
示例#2
0
def test_append():
    do = DataObject.create(TEST_CONTENT1)
    DataObject.append_chunk(do.uuid, 1, TEST_CONTENT2)
    DataObject.append_chunk(do.uuid, 2, TEST_CONTENT3)
    DataObject.append_chunk(do.uuid, 3, TEST_CONTENT4)
    do = DataObject.find(do.uuid)
    data = []
    for chk in do.chunk_content():
        data.append(chk)
    assert b"".join(data) == b'This is a test.'
    DataObject.delete_id(do.uuid)

    do = DataObject.create(TEST_CONTENT1, compressed=True)
    DataObject.append_chunk(do.uuid, 1, TEST_CONTENT2, True)
    DataObject.append_chunk(do.uuid, 2, TEST_CONTENT3, True)
    DataObject.append_chunk(do.uuid, 3, TEST_CONTENT4, True)
    do = DataObject.find(do.uuid)
    data = []
    for chk in do.chunk_content():
        data.append(chk)
    assert b"".join(data) == b'This is a test.'
    DataObject.delete_id(do.uuid)
示例#3
0
 def append_data_object(self, uuid, seq_num, raw_data):
     """Add a chunk of data in an existing data object"""
     DataObject.append_chunk(uuid, raw_data, seq_num,
                             settings.COMPRESS_UPLOADS)