From: Ross Bamford Date: 2006-11-11T19:35:08+09:00 Subject: Re: Trying to get pack to work with the * template character On Fri, 10 Nov 2006 01:21:38 -0000, John Hahn wrote: > Ok, here's a snippet of my code. > > @image_array = Array.new > @image = File.open("test.JPG", "rb") do |image| > image.each_byte{|ch| @image_array << ch.to_s} > end > @temp = @image_array.pack("m*") > > when I display the value of @temp.. only the first element of > @image_array has been packed.. any idea why the * isn't working? I > thought the * meant that it would cycle through the entire array and > convert each element... any ideas? > As Tim said, ruby does include a base64 library which will probably do what you want, but if you're determined to use pack you need to know that 'm' expects a binary string as it's argument. 'm*' expects one or more binary strings. So in this case, you just need 'm' like so: [File.read('test.JPG')].pack('m') or possibly: [File.open('test.JPG','rb') { |f| f.read }].pack('m') -- Ross Bamford - rosco@roscopeco.remove.co.uk