def chunk_generator(chunk_count, chunk_size, file_data):
    """
    Generic chunk generator logic

    :param chunk_count: Number of chunks wanted
    :param chunk_size: Size of each chunk
    :param file_data: bytes to be split into chunk
    :return:
    """
    try:
        total_len = len(file_data)
        is_fp = False
    except TypeError:
        total_len = get_file_size(file_data)
        is_fp = True
    for i in range(chunk_count):
        start_range = i * chunk_size
        end_range = (start_range + chunk_size) if i < (chunk_count - 1) else total_len
        chunk_info = Chunk(i, start_range, end_range, chunk_count)
        if is_fp:
            file_data.seek(chunk_info.start, os.SEEK_SET)
            yield chunk_info, file_data.read(chunk_info.length)
        else:
            yield chunk_info, file_data[chunk_info.start: chunk_info.end]

    Generic chunk generator logic

    :param chunk_count: Number of chunks wanted
    :param chunk_size: Size of each chunk
    :param file_data: bytes to be split into chunk
    :return:
    
instagram_private_api/utils.py