'Converts a Markdown file and returns the HTML as a Unicode string.
Decodes the file using the provided encoding (defaults to utf-8),
passes the file content to markdown, and outputs the html to either
the provided stream or the file with provided name, using the same
encoding as the source file. The \'xmlcharrefreplace\' error handler is
used when encoding the output.
**Note:** This is the only place that decoding and encoding of Unicode
takes place in Python-Markdown.  (All other code is Unicode-in /
Unicode-out.)
Keyword arguments:
* input: File object or path. Reads from stdin if `None`.
* output: File object or path. Writes to stdout if `None`.
* encoding: Encoding of input and output files. Defaults to utf-8.'

def convertFile(self, input=None, output=None, encoding=None):

    encoding = (encoding or u'utf-8')
    if input:
        if isinstance(input, util.string_type):
            input_file = codecs.open(input, mode=u'r', encoding=encoding)
        else:
            input_file = codecs.getreader(encoding)(input)
        text = input_file.read()
        input_file.close()
    else:
        text = sys.stdin.read()
        if (not isinstance(text, util.text_type)):
            text = text.decode(encoding)
    text = text.lstrip(u'\ufeff')
    html = self.convert(text)
    if output:
        if isinstance(output, util.string_type):
            output_file = codecs.open(output, u'w', encoding=encoding, errors=u'xmlcharrefreplace')
            output_file.write(html)
            output_file.close()
        else:
            writer = codecs.getwriter(encoding)
            output_file = writer(output, errors=u'xmlcharrefreplace')
            output_file.write(html)
    else:
        html = html.encode(encoding, u'xmlcharrefreplace')
        try:
            sys.stdout.buffer.write(html)
        except AttributeError:
            sys.stdout.write(html)
    return self
