def block_hash_file(self, archipelagoobject): """Return the list of hashes (hashes map) for the blocks in a buffered file. Helper method, does not affect store. """ hashes = [] append = hashes.append block_hash = self.block_hash for block in file_sync_read_chunks(archipelagoobject, self.blocksize, 1, 0): append(block_hash(block)) return hashes
def block_stor_file(self, archipelagoobject): """Read blocks from buffered file object and store them. Return: (bytes read, list of hashes, list of hashes that were missing) """ blocksize = self.blocksize block_stor = self.block_stor hashlist = [] hextend = hashlist.extend storedlist = [] sextend = storedlist.extend lastsize = 0 for block in file_sync_read_chunks(archipelagoobject, blocksize, 1, 0): hl, sl = block_stor((block,)) hextend(hl) sextend(sl) lastsize = len(block) size = (len(hashlist) - 1) * blocksize + lastsize if hashlist else 0 return size, hashlist, storedlist
def block_stor_file(self, archipelagoobject): """Read blocks from buffered file object and store them. Return: (bytes read, list of hashes, list of hashes that were missing) """ blocksize = self.blocksize block_stor = self.block_stor hashlist = [] hextend = hashlist.extend storedlist = [] sextend = storedlist.extend lastsize = 0 for block in file_sync_read_chunks(archipelagoobject, blocksize, 1, 0): hl, sl = block_stor((block, )) hextend(hl) sextend(sl) lastsize = len(block) size = (len(hashlist) - 1) * blocksize + lastsize if hashlist else 0 return size, hashlist, storedlist