def _download_data(self, response, file_path):
    ret = bytearray()
    total_length = response.headers.get('content-length')
    if (total_length is None):
        if (not file_path):
            ret += response.content
        else:
            if self.output:
                total_length = len(response.content)
                progress = human_readable_progress(total_length, total_length)
                print_progress(self.output, 50, progress)
            save_append(file_path, response.content)
    else:
        total_length = int(total_length)
        encoding = response.headers.get('content-encoding')
        gzip = (encoding == 'gzip')

        def download_chunks(file_handler=None, ret_buffer=None):
            'Write to a buffer or to a file handler'
            chunk_size = (1024 if (not file_path) else (1024 * 100))
            download_size = 0
            last_progress = None
            for data in response.iter_content(chunk_size):
                download_size += len(data)
                if (ret_buffer is not None):
                    ret_buffer.extend(data)
                if (file_handler is not None):
                    file_handler.write(to_file_bytes(data))
                if self.output:
                    units = progress_units(download_size, total_length)
                    progress = human_readable_progress(download_size, total_length)
                    if (last_progress != units):
                        print_progress(self.output, units, progress)
                        last_progress = units
            return download_size
        if file_path:
            mkdir(os.path.dirname(file_path))
            with open(file_path, 'wb') as handle:
                dl_size = download_chunks(file_handler=handle)
        else:
            dl_size = download_chunks(ret_buffer=ret)
        response.close()
        if ((dl_size != total_length) and (not gzip)):
            raise ConanException(('Transfer interrupted before complete: %s < %s' % (dl_size, total_length)))
    if (not file_path):
        return bytes(ret)
    else:
        return
def _download_data(self, response, file_path):
    ret = bytearray()
    total_length = response.headers.get('content-length')
    if (total_length is None):
        if (not file_path):
            ret += response.content
        else:
            if self.output:
                total_length = len(response.content)
                progress = human_readable_progress(total_length, total_length)
                print_progress(self.output, 50, progress)
            save_append(file_path, response.content)
    else:
        total_length = int(total_length)
        encoding = response.headers.get('content-encoding')
        gzip = (encoding == 'gzip')

        def download_chunks(file_handler=None, ret_buffer=None):
            'Write to a buffer or to a file handler'
            chunk_size = (1024 if (not file_path) else (1024 * 100))
            download_size = 0
            last_progress = None
            for data in response.iter_content(chunk_size):
                download_size += len(data)
                if (ret_buffer is not None):
                    ret_buffer.extend(data)
                if (file_handler is not None):
                    file_handler.write(to_file_bytes(data))
                if self.output:
                    units = progress_units(download_size, total_length)
                    progress = human_readable_progress(download_size, total_length)
                    if (last_progress != units):
                        print_progress(self.output, units, progress)
                        last_progress = units
            return download_size
        if file_path:
            mkdir(os.path.dirname(file_path))
            with open(file_path, 'wb') as handle:
                dl_size = download_chunks(file_handler=handle)
        else:
            dl_size = download_chunks(ret_buffer=ret)
        response.close()
        if ((dl_size != total_length) and (not gzip)):
            raise ConanException(('Transfer interrupted before complete: %s < %s' % (dl_size, total_length)))
    if (not file_path):
        return bytes(ret)
    else:
        return