class Curl::Easy
def download(url, filename = url.split(/\?/).first.split(/\//).last, &blk)
offending chunk will *not* be written to the file, the file will be closed,
returns a size that differs from the data chunk size - in this case, the
necessary. As usual, the transfer will be aborted if the on_body handler
to the file, allowing the handler to perform mutative operations where
data string is passed to the handler *before* it is written
download, to account for the automatic routing of data to the specified file: The
*Note* that the semantics of the on_body handler are subtly changed when using
perform call.
If a block is supplied, it will be passed the curl instance prior to the
usually be the filename most simple urls).
supplied filename (defaults to the last component of the URL path, which will
Stream the specified url (via perform) and save the data directly to the
Curl::Easy.download(url, filename = url.split(/\?/).first.split(/\//).last) { |curl| ... }
call-seq:
def download(url, filename = url.split(/\?/).first.split(/\//).last, &blk) curl = Curl::Easy.new(url, &blk) output = if filename.is_a? IO filename.binmode if filename.respond_to?(:binmode) filename else File.open(filename, 'wb') end begin old_on_body = curl.on_body do |data| result = old_on_body ? old_on_body.call(data) : data.length output << data if result == data.length result end curl.perform ensure output.close rescue IOError end return curl end