Ross Bamford
11/11/2006 10:34:00 AM
On Fri, 10 Nov 2006 01:21:38 -0000, John Hahn <jchahn@cox.net> wrote:
> Ok, here's a snippet of my code.
>
> @image_array =3D Array.new
> @image =3D File.open("test.JPG", "rb") do |image|
> image.each_byte{|ch| @image_array << ch.to_s}
> end
> @temp =3D @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 tha=
t =
'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