Download Zipfile via CURL to the actual Zip file in your file structure

I am trying to create a file loader with RubyGem Curb. (See This Question .)

I am trying to upload a zip file and then with a class file. I am trying to make a file so that I can double-click it in Finder (I'm on OS X). How am I going to convert this body "Curl'ed" to a zip file.

require 'rubygems' require 'curb' class Download def start curl = Curl::Easy.new('http://wordpress.org/latest.zip') curl.perform curl.on_body { |d| f = File.new('test.zip', 'w') {|f| f.write d} } end end dl = Download.new dl.start 

I am not getting any error and I cannot find the file. I tried absolute paths no difference.

+4
source share
2 answers

You add the on_body event after the perform call, which passes the body. If you move an event declaration before a call to perform , this should work.

+2
source

I am using ruby ​​2.0

and my code is:

 curl = Curl::Easy.new('http://somepage.cz/index.html') curl.on_body do |d| f = File.open('output_file.html', 'w') {|f| f.write(d)} end curl.perform 

I had to change File.new to File.open without this so that it would not work. Moving curl.perfom at the end helped me.

+4
source

Source: https://habr.com/ru/post/1344670/


All Articles