def read_buffer(io, print_output=False, print_func=None):
    '''
    Reads a file-like buffer object into lines and optionally prints the output.
    '''
    def _print(line):
        if print_output:
            if print_func:
                formatted_line = print_func(line)
            else:
                formatted_line = line
            encoded_line = unicode(formatted_line).encode('utf-8')
            print(encoded_line)
    out = []
    for line in io:
        if not isinstance(line, six.text_type):
            line = line.decode('utf-8')
        line = line.strip()
        out.append(line)
        _print(line)
    return out