Starts retrieving the remote file and returns an IO-like object which
 downloads the response body on-demand. Accepts wget command-line options.
340951
def open(url, *args, rewindable: true, **options)
      arguments = generate_command(url, *args, **options)

      command = Down::Wget::Command.execute(arguments)
      # Wrap the wget command output in an IO-like object.
      output  = Down::ChunkedIO.new(
        chunks:     command.enum_for(:output),
        on_close:   command.method(:terminate),
        rewindable: false,
      )

      # https://github.com/tmm1/http_parser.rb/issues/29#issuecomment-309976363
      header_string  = output.readpartial
      header_string << output.readpartial until header_string.include?("\r\n\r\n")
      header_string, first_chunk = header_string.split("\r\n\r\n", 2)

      # Use an HTTP parser to parse out the response headers.
      parser = HTTP::Parser.new
      parser << header_string

      if parser.headers.nil?
        output.close
        raise Down::Error, "failed to parse response headers"
      end

      headers = parser.headers
      status  = parser.status_code

      content_length = headers["Content-Length"].to_i if headers["Content-Length"]
      charset        = headers["Content-Type"][/;\s*charset=([^;]+)/i, 1] if headers["Content-Type"]

      # Create an Enumerator which will lazily retrieve chunks of response body.
      chunks = Enumerator.new do |yielder|
        yielder << first_chunk if first_chunk
        yielder << output.readpartial until output.eof?
      end

      Down::ChunkedIO.new(
        chunks:     chunks,
        size:       content_length,
        encoding:   charset,
        rewindable: rewindable,
        on_close:   output.method(:close),
        data:       { status: status, headers: headers },
      )
    end
750833
def download_file_powershell(url, target, headers={}):
    
    target = os.path.abspath(target)

    powershell_cmd = "$request = (new-object System.Net.WebClient);"
    for k, v in headers.items():
        powershell_cmd += "$request.headers['%s'] = '%s';" % (k, v)
    powershell_cmd += "$request.DownloadFile(%(url)r, %(target)r)" % vars()

    cmd = [
        'powershell',
        '-Command',
        powershell_cmd,
    ]

    _clean_check(cmd, target)
295
def load_remote_system(url, format=None):
    '''
    '''
    filename, headers = urlretrieve(url)
    return load_system(filename, format=format)
817073
def download(self, filename=None):
        
        if filename is None:
            filename = self.name
        with self.remote_open() as infile:
            with open(filename, 'wb') as outfile:
                outfile.write(infile.read())
650940
def download(self, url, file):
        
        if isinstance(file, str) or isinstance(file, unicode):
            file = open(file, 'wb')
        webclient = self.dupe()
        webclient.request('GET', url)
        rsp = webclient.getresponse()
        self._currdl = rsp
        self._dlfile = file
        for chunk in iter(lambda: rsp.read(16384), ''):
            file.write(chunk)
        self._currdl = None
        file.close()
879866
def download_file(cls, url, local_file_name=None, force=False, chunk_size=1024):
        

        local_file_name = local_file_name if local_file_name else url.split('/')[-1]
        filepath = os.path.join(cls.data_path, local_file_name)

        if not os.path.exists(filepath) or force:
            try:
                headers = requests.head(url, allow_redirects=True).headers
                length = headers.get('Content-Length')

                logger.info("Starting download of {} file with {} bytes ...".format(url, length))

                widgets = [
                    'Downloading file please wait...', progressbar.Percentage(),
                    ' ', progressbar.Bar(),
                    ' ', progressbar.ETA(),
                    ' ', progressbar.FileTransferSpeed(),
                ]
                bar = progressbar.ProgressBar(widgets=widgets, max_value=int(length) + chunk_size).start()

                r = requests.get(url, stream=True)

                with open(filepath, 'wb') as f:
                    total_chunk = 0

                    for chunk in r.iter_content(chunk_size):
                        if chunk:
                            f.write(chunk)
                            total_chunk += chunk_size
                            bar.update(total_chunk)

                bar.finish()

            except:
                if os.path.exists(filepath):
                    os.remove(filepath)

                raise

        return filepath
245206
def stream_download(url, target_path, verbose=False):
    
    response = requests.get(url, stream=True)
    handle = open(target_path, "wb")
    if verbose:
        print("Beginning streaming download of %s" % url)
        start = datetime.now()
        try:
            content_length = int(response.headers['Content-Length'])
            content_MB = content_length/1048576.0
            print("Total file size: %.2f MB" % content_MB)
        except KeyError:
            pass      # allow Content-Length to be missing
    for chunk in response.iter_content(chunk_size=512):
        if chunk:     # filter out keep-alive new chunks
            handle.write(chunk)
    if verbose:
        print(
            "Download completed to %s in %s" %
            (target_path, datetime.now() - start))
871980
def download_file(url):
    
    response = requests.get(url)
    if response.status_code is not 200:
        return None
    return response.text
266647
def retrieve_http(options)
        file_size = options.fetch(:file_size)
        headers = options.fetch(:headers)
        url = options.fetch(:url)
        retrieved = 0

        request = Typhoeus::Request.new(url.to_s, method: :get, headers: headers)
        request.on_headers do |response|
          raise DownloadError.new("#{self.class}: Failed to download #{url}: Status Code: #{response.code}", response) unless response.code == 200
        end
        request.on_body do |chunk|
          retrieved += chunk.bytesize
          yield(chunk, retrieved, file_size)
        end
        request.run
      end
1100736
def download_file(self, remote, local):
        
        file = open(local, 'wb')
        try:
            self.download(remote, file)
        finally:
            file.close()
1186563
def download(self, uri, file_path):
        
        with open(file_path, 'wb') as file:
            return self._connection.download_to_stream(file, uri)
417304
def download(remote_location, remotes=None, prefix="", dry_run=False):
    
    if remotes is None:
        remotes, _ = _resources_files(
            abs_paths=remote_location.startswith('s3://'))
    if remote_location.startswith('s3://'):
        from .s3 import S3Backend
        backend = S3Backend(remote_location, dry_run=dry_run)
        backend.download(list_local(remotes, prefix), prefix)
    else:
        dest_root = '.'
        shell_command([
                '/usr/bin/rsync',
                '-thrRvz', '--rsync-path', '/usr/bin/rsync',
                '%s/./' % remote_location, dest_root], dry_run=dry_run)
188809
def download_url(self, remote_path, **kwargs):
        

        def get_url(dlink):
            return self.session.get(dlink,
                                    headers=BAIDUPAN_HEADERS,
                                    stream=True).url

        if not hasattr(self, 'dsign'):
            self.get_sign()

        if isinstance(remote_path, str) or isinstance(remote_path, str):
            remote_path = [remote_path]

        file_list = []
        jdata = json.loads(self.meta(remote_path).content)
        if jdata['errno'] != 0:
            jdata = self.__err_handler('generic', jdata['errno'],
                                       self.meta,
                                       args=(remote_path,)
                                       )
        logging.debug('[*]' + str(jdata))
        for i, entry in enumerate(jdata['info']):
            url = entry['dlink']
            foo = get_url(url)
            if 'wenxintishi' in foo:
                file_list.append(self._yunguanjia_format(remote_path[i]))
            else:
                file_list.append(get_url(entry['dlink']))

        return file_list
802565
public File downloadFileFromResponse(Response response) throws ApiException {
        try {
            File file = prepareDownloadFile(response);
            BufferedSink sink = Okio.buffer(Okio.sink(file));
            sink.writeAll(response.body().source());
            sink.close();
            return file;
        } catch (IOException e) {
            throw new ApiException(e);
        }
    }
736667
def download_box(uri)
      require 'net/http'
      require 'uri'
      url = uri.path
      # Download file to bebox boxes tmp
      Net::HTTP.start(uri.host) do |http|
        response = http.request_head(URI.escape(url))
        write_remote_file(uri, http, response)
      end
    end
1364476
public Response download(String url, File destination) throws IOException {
		return download(url, destination, (String[]) null);
	}
347942
def download_http(source: str, file: Union[str, BinaryIO], log: logging.Logger,
                  chunk_size: int=DEFAULT_DOWNLOAD_CHUNK_SIZE) -> None:
    
    log.info("Fetching %s...", source)
    r = requests.get(source, stream=True)
    if r.status_code != 200:
        log.error(
            "An error occurred while fetching the model, with code %s" % r.status_code)
        raise ValueError
    if isinstance(file, str):
        os.makedirs(os.path.dirname(file), exist_ok=True)
        f = open(file, "wb")
    else:
        f = file
    try:
        total_length = int(r.headers.get("content-length"))
        num_chunks = math.ceil(total_length / chunk_size)
        if num_chunks == 1:
            f.write(r.content)
        else:
            for chunk in progress_bar(
                    r.iter_content(chunk_size=chunk_size),
                    log,
                    expected_size=num_chunks):
                if chunk:
                    f.write(chunk)
    finally:
        if isinstance(file, str):
            f.close()