Esempio n. 1
0
    def _create_file(self, size):
        """Create a file and compute its merkle hash"""

        tmp_file = NamedTemporaryFile()
        self.debug('\tCreate file %s  ' % tmp_file.name)
        meta = self.clients.pithos.get_container_info()
        block_size = int(meta['x-container-block-size'])
        block_hash_algorithm = meta['x-container-block-hash']
        num_of_blocks = size / block_size
        hashmap = HashMap(block_size, block_hash_algorithm)
        s = 0
        for i in range(num_of_blocks):
            seg = urandom(block_size)
            tmp_file.write(seg)
            hashmap.load(seg)
            s += len(seg)
        else:
            rest = size - s
            if rest:
                seg = urandom(rest)
                tmp_file.write(seg)
                hashmap.load(seg)
                s += len(seg)
        tmp_file.seek(0)
        tmp_file.hash = hexlify(hashmap.hash())
        return tmp_file
Esempio n. 2
0
    def _create_file(self, size):
        """Create a file and compute its merkle hash"""

        tmp_file = NamedTemporaryFile()
        self.debug('\tCreate file %s  ' % tmp_file.name)
        meta = self.clients.pithos.get_container_info()
        block_size = int(meta['x-container-block-size'])
        block_hash_algorithm = meta['x-container-block-hash']
        num_of_blocks = size / block_size
        hashmap = HashMap(block_size, block_hash_algorithm)
        s = 0
        for i in range(num_of_blocks):
            seg = urandom(block_size)
            tmp_file.write(seg)
            hashmap.load(seg)
            s += len(seg)
        else:
            rest = size - s
            if rest:
                seg = urandom(rest)
                tmp_file.write(seg)
                hashmap.load(seg)
                s += len(seg)
        tmp_file.seek(0)
        tmp_file.hash = hexlify(hashmap.hash())
        return tmp_file