Replacing Curl – part 1 of many

Let the whine begin. Aka, bug report with attitude. Shoes-3.2b4 for Windows craps out running sample/simpler-downloader.rb. On the pi, it does a segfault. shoes/http/curl.c and shoes/http/download.c,winhttp.c. Works fine for x86_64 and i686. The last thing I want to do is debug either of the failures. I could (have done before) include curl in the Windows builds. Every time I look at curl configuration and curl internals and the shoes code for use it, I shudder violently. If there is a better way to do downloads now than when _why wrote all that code, I want to find that way. Shoes downloads in two situtations – a uri in a image load and a call to download. I’ll fix the download method first and then the image and then if that works, do a major overhaul of the .c and .h and all the rake files to remove curl/winhttp. If I can.

I’m borrowing from the Shoes4 code – their api is the ‘future’ although they claim it is based on 3.1. I’m going with what it is in the Shoes Manual unless it’s too obscure or annoying. If there is API breakage so be it. I’ll create a download.rb in lib/shoes/ and require it from cache.rb (not the best place – it should be part of Shoes.rb – but who cares?)

So, lib/shoes/download.rb looks like this
# My ruby downloader move code to shoes.rb or lib/shoes/ when working
class Shoes
class Download
# need headers, body, status @vars as well as the Shoes4 stuff
attr_reader :progress, :content_length, :headers, :body, :status
def initialize url, opts, &blk
@blk = blk
start_download url, opts
end

def start_download url, opts
puts "Download from #{url} with #{opts}"
end
end
end

# Monkey patch over the 'C' code.
class Shoes::Types::App
# Shoes::Types::App seems wrong but it works.
def download (url, options, &blk)
Shoes::Download.new(url, options, &blk)
end
end

When I run samples/simple-downloader.rb I get

Download from http://shoes.mvmanila.com with {:save=>"shoes.mvmanila.com", :progress=>(Proc |a|), :finish=>(Proc |a|)}

So I can replace ‘C’ code with Ruby code. I knew that should work but a test is needed to prove it. Will the rest of the Shoes4 code work? I suspect not but it’s a good place to start from.

Leave a Reply

Your email address will not be published. Required fields are marked *