Forum & binary cgi

I too am new to Ruby, but i love it! Two questions though:

  1. I read and printed a png image from disk and printed it to the
    browser but it doesnt’t work:

    print "Content-type: image/png\n\n"
    file = File.new(imagePath, ‘r’)
    content = ''
    file.each_line {|line| content += line }
    file.close
    print content

Could this have anything to do with binary mode? How could i get this to
work?

  1. What is the forum/community site where most Ruby experts hang out?
    Like Perl has perlmonks.org

Thanks in advance,

Teun van Eijsden
The Netherlands

I too am new to Ruby, but i love it! Two questions though:

  1. I read and printed a png image from disk and printed it to the
    browser but it doesnt’t work:

print “Content-type: image/png\n\n”
file = File.new(imagePath, ‘r’)
content = ‘’
file.each_line {|line| content += line }
file.close
print content

Could this have anything to do with binary mode? How could i get this to
work?

Try this:

print “Content-type: image/png\n\n”
File.open(image_path, ‘rb’) do |file|
content = file.read
end # file is auto-closed here
print content

Explicitly closing a file is so last-century :wink:

You can use ‘content = File.read(image_path)’ but I’m not sure if
that’s read as text or binary.

  1. What is the forum/community site where most Ruby experts hang out?
    Like Perl has perlmonks.org

No real forum to speak of. That’s what ruby-talk is for.

Check out the Ruby Documentation Bundle (Ruby-Doc.org: Documenting the Ruby Language) for
some meaty documentation and a newbie’s guide to the Ruby community.
Summary: ruby-talk, IRC, rubygarden.org, Wiki, RAA, RubyForge.

Cheers,
Gavin

···

On Sunday, December 28, 2003, 9:11:49 AM, Jaap wrote:

Gavin Sinclair wrote:

Try this:

print “Content-type: image/png\n\n”
File.open(image_path, ‘rb’) do |file|
content = file.read
end # file is auto-closed here
print content

Thank you very much. It works if i add STDOUT.binmode
Now if i can only get those damn multipart file uploads working…

Teun