unzip process exception. dunno why

J

Junkone

i get an error Got exception can't convert Tempfile into String. This
happens right at the line Zip::ZipFile.open(source) do |zipfile|
I have passed the downloaded file block to the source variable.
any help is appreciated.
The intend is to download the http://www.dtniq.com/product/mktsymbols_v2.zip
and unzip it to teh temp folder.


require 'rubygems'
require 'open-uri'
require 'zip/zipfilesystem'
# source should be a zip file.
# target should be a directory to output the contents to.
def unzip_file(source, target)
# Create the target directory.
# We'll ignore the error scenario where
begin
Dir.mkdir(target) unless File.exists? target
end
puts "going to open the zip file"
Zip::ZipFile.open(source) do |zipfile|
dir = zipfile.dir
puts dir.to_s
dir.entries('.').each do |entry|
puts "#{target}/#{entry}"
zipfile.extract(entry, "#{target}/#{entry}")
end
end

rescue Zip::ZipDestinationFileExistsError => ex
puts "ignore error "
# I'm going to ignore this and just overwrite the files.
rescue => ex
puts "Got exception " + ex
end





url = 'http://www.dtniq.com/product/mktsymbols_v2.zip'
open(url, 'r') do |fo|
puts "unzipfile "
unzip_file(fo, "c:\\temp11\\")
fo.print open('http://wordpress.org/latest.zip').read
end
 
J

Junkone

 Zip::ZipFile.open(source) - source should be the name of the zip file (seehttp://rubyzip.sourceforge.net/classes/Zip/ZipFile.html#M000143)

You have already opened the file and are passing in the file object

cheers

you mean i should only pass the file name and path of the zipfile.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,725
Members
45,511
Latest member
Osiris-Team

Latest Threads

Top