def entry_assemble(entry_fields, ecc_params, header_size, filepath, fileheader=None):
    '''From an entry with its parameters (filename, filesize), assemble a list of each block from the original file along with the relative hash and ecc for easy processing later.'''
    # Extract the header from the file
    if fileheader is None:
        with open(filepath, 'rb') as file: # filepath is the absolute path to the original file (the one with maybe corruptions, NOT the output repaired file!)
            # Compute the size of the buffer to read: either header_size if possible, but if the file is smaller than that then we will read the whole file.
            if entry_fields["filesize"] > 0 and entry_fields["filesize"] < header_size:
                fileheader = file.read(entry_fields["filesize"])
            else:
                fileheader = file.read(header_size)

    # Cut the header and the ecc entry into blocks, and then assemble them so that we can easily process block by block
    entry_asm = []
    for i, j in itertools.izip(xrange(0, len(fileheader), ecc_params["message_size"]), xrange(0, len(entry_fields["ecc_field"]), ecc_params["hash_size"] + ecc_params["ecc_size"])):
        # Extract each fields from each block
        mes = fileheader[i:i+ecc_params["message_size"]]
        hash = entry_fields["ecc_field"][j:j+ecc_params["hash_size"]]
        ecc = entry_fields["ecc_field"][j+ecc_params["hash_size"]:j+ecc_params["hash_size"]+ecc_params["ecc_size"]]
        entry_asm.append({"message": mes, "hash": hash, "ecc": ecc})

    # Return a list of fields for each block
    return entry_asm
def entry_assemble ( entry_fields , ecc_params , header_size , filepath , fileheader = None ) : if fileheader is None : with open ( filepath , 'rb' ) as file : if entry_fields [ "filesize" ] > 0 and entry_fields [ "filesize" ] < header_size : fileheader = file . read ( entry_fields [ "filesize" ] ) else : fileheader = file . read ( header_size ) entry_asm = [ ] for i , j in itertools . izip ( xrange ( 0 , len ( fileheader ) , ecc_params [ "message_size" ] ) , xrange ( 0 , len ( entry_fields [ "ecc_field" ] ) , ecc_params [ "hash_size" ] + ecc_params [ "ecc_size" ] ) ) : mes = fileheader [ i : i + ecc_params [ "message_size" ] ] hash = entry_fields [ "ecc_field" ] [ j : j + ecc_params [ "hash_size" ] ] ecc = entry_fields [ "ecc_field" ] [ j + ecc_params [ "hash_size" ] : j + ecc_params [ "hash_size" ] + ecc_params [ "ecc_size" ] ] entry_asm . append ( { "message" : mes , "hash" : hash , "ecc" : ecc } ) return entry_asm
From an entry with its parameters (filename, filesize), assemble a list of each block from the original file along with the relative hash and ecc for easy processing later.