Revision c4bff6ac

b/kamaki/clients/pithos.py
80 80
        meta = self.get_container_meta(self.container)
81 81
        blocksize = int(meta['block-size'])
82 82
        blockhash = meta['block-hash']
83
        
84
        file_size = size if size is not None else os.fstat(f.fileno()).st_size
83

  
84
        size = size if size is not None else os.fstat(f.fileno()).st_size
85 85
        nblocks = 1 + (file_size - 1) // blocksize
86 86
        hashes = []
87 87
        map = {}
88 88

  
89
        size = 0
90
        
89
        offset = 0
90

  
91 91
        if hash_cb:
92 92
            hash_gen = hash_cb(nblocks)
93 93
            hash_gen.next()
94
    
94

  
95 95
        for i in range(nblocks):
96
            block = f.read(blocksize)
96
            block = f.read(min(blocksize, size - offset))
97 97
            bytes = len(block)
98 98
            hash = pithos_hash(block, blockhash)
99 99
            hashes.append(hash)
100
            map[hash] = (size, bytes)
101
            size += bytes
100
            map[hash] = (offset, bytes)
101
            offset += bytes
102 102
            if hash_cb:
103 103
                hash_gen.next()
104
        
105
        assert size == file_size
106
                
104

  
105
        assert offset == size
106

  
107 107
        path = '/%s/%s/%s' % (self.account, self.container, object)
108 108
        params = dict(format='json', hashmap='')
109 109
        hashmap = dict(bytes=size, hashes=hashes)

Also available in: Unified diff