def _count_lines(file_obj):
    """Counts number of lines in given file."""
    lines = 0
    buf_size = 1024 * 1024
    read_f = file_obj.read
    buf = read_f(buf_size)
    while buf:
        lines += buf.count(b'\n')
        buf = read_f(buf_size)
    return lines
