1

I have understood that I could use the RubyGem Curb to fulfill my needs of curl'ing down a file to my computer. But I cannot figure out how to actually "touch" the file. This is what I have got so far

include 'rubygems'
include 'curb'

curl = Curl::Easy.new('http://wordpress.org/latest.zip')
curl.perform

I think I understand that perform actually downloads the file. But how can I interact with the file afterwards? Where is it downloaded to?

Regards, Mattias

maetthew
  • 191
  • 2
  • 14
  • possible duplicate of [Download a zip file through Net::HTTP](http://stackoverflow.com/questions/5386159/download-a-zip-file-through-nethttp) – the Tin Man Mar 22 '11 at 05:35

2 Answers2

3

The file can be accessed with the body_str method.

puts curl.body_str
ghoppe
  • 21,452
  • 3
  • 30
  • 21
2

Check the docs at http://rdoc.info/gems/curb/0.7.15/.

After perform, the content is in e.g. curl.body_str.

Ilkka
  • 2,644
  • 1
  • 23
  • 27
  • How would I go about to convert this to an actual zip-file I can open in Finder (I am using OSX). – maetthew Mar 21 '11 at 19:55
  • I have tried `file = File.new("test.zip", "w+") file.puts $filebody file.close` – maetthew Mar 21 '11 at 19:57
  • Should I perhhaps post a new question instead? :) – maetthew Mar 21 '11 at 19:59
  • Probably best to write an `on_body` handler, something like `curl.on_body {|d| File.open('your.zip', 'a') {|f| f.write d} }`. – Ilkka Mar 21 '11 at 20:00
  • I think `puts` adds an extra newline, that'd break your zipfile. – Ilkka Mar 21 '11 at 20:01
  • It is not working. I posted a new [question here](http://stackoverflow.com/questions/5383143/zipfile-download-through-curl-to-an-actual-zip-file-in-your-file-structure) – maetthew Mar 21 '11 at 20:19