import chardet


def encode_utf8(raw_data):
    # Detect the encoding of the file
    encoding = chardet.detect(raw_data)['encoding']

    # Decode the file based on the detected encoding
    if encoding == 'utf-8':
        content = raw_data.decode('utf-8').encode('utf-8')
    elif encoding == 'latin-1':
        content = raw_data.decode('latin-1').encode('utf-8')
    elif encoding == 'ascii':
        content = raw_data.decode('ascii').encode('utf-8')
    else:
        raise ValueError(f"Unsupported encoding: {encoding}")

    return content
