def write_to_file(filename, data, chunksize=8192):
    """
    Write bytes from data into file
    
    :param filename: name of file
    :param data: list with data (turned into bytearrays)
    :param chunksize: the bit-size which is transmitted at once
    """
    with open(filename, 'wb') as f:
        loc = 0
        length = len(data)
        while True:
            if loc + chunksize < length:
                chunk = data[loc:loc + chunksize]
                f.write(chunk)
                loc += chunksize
            else:
                chunk = data[loc:length]
                f.write(chunk)
                break
