[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Base64 packing question

John Sands

12/3/2004 11:36:00 PM

I'm packing up a file into an e-mail attachment using base64 encoding
and I'm only getting the first line of the file. I've discovered that
it's a misunderstanding I have about the pack method:

irb(main):001:0> ["a", "b", "c"].pack("m").unpack("m")
=> ["a"]

How do I get the whole array packed?


5 Answers

Sam Roberts

12/4/2004 12:27:00 AM

0

Quoteing sandspace@gmail.com, on Sat, Dec 04, 2004 at 08:36:11AM +0900:
> I'm packing up a file into an e-mail attachment using base64 encoding
> and I'm only getting the first line of the file. I've discovered that
> it's a misunderstanding I have about the pack method:
>
> irb(main):001:0> ["a", "b", "c"].pack("m").unpack("m")
> => ["a"]
>
> How do I get the whole array packed?

Not sure why you think that pack wil concatenate the array before
base64ing it. Check out lib/base64.rb in the ruby lib directory for
an example of base64 encoding/decoding.

Sam



John Sands

12/4/2004 1:05:00 AM

0

Thanks. It works now.

I did it that way because The Ruby Way (page 92) has "the easiest way
to do a base64 encode/decode is the use the built-in features of Ruby.
The Array class has a pack method..." and it doesn't mention the
base64 class; so I didn't look for one.

Thanks.


On Sat, 4 Dec 2004 09:27:17 +0900, Sam Roberts <sroberts@uniserve.com> wrote:
> Quoteing sandspace@gmail.com, on Sat, Dec 04, 2004 at 08:36:11AM +0900:
>
>
> > I'm packing up a file into an e-mail attachment using base64 encoding
> > and I'm only getting the first line of the file. I've discovered that
> > it's a misunderstanding I have about the pack method:
> >
> > irb(main):001:0> ["a", "b", "c"].pack("m").unpack("m")
> > => ["a"]
> >
> > How do I get the whole array packed?
>
> Not sure why you think that pack wil concatenate the array before
> base64ing it. Check out lib/base64.rb in the ruby lib directory for
> an example of base64 encoding/decoding.
>
> Sam
>
>


Eric Hodel

12/4/2004 2:14:00 AM

0


On 03 Dec 2004, at 15:36, John Sands wrote:

> I'm packing up a file into an e-mail attachment using base64 encoding
> and I'm only getting the first line of the file. I've discovered that
> it's a misunderstanding I have about the pack method:
>
> irb(main):001:0> ["a", "b", "c"].pack("m").unpack("m")
> => ["a"]
>
> How do I get the whole array packed?

The Array in Array#pack is like a C struct, and the argument to pack is
the format string to pack the Array into, so ["a", "b", "c"].pack "m"
only packs one of the strings you provided.

You certainly don't want to pack the strings individually (["a", "b",
"c"].pack "mmm"), instead you simply need to join the Array before
packing:

body = ["a", "b", "c"].join("\n")

[body].pack("m")



Sam Roberts

12/4/2004 4:00:00 AM

0

Quoteing sandspace@gmail.com, on Sat, Dec 04, 2004 at 10:04:55AM +0900:
> Thanks. It works now.
>
> I did it that way because The Ruby Way (page 92) has "the easiest way
> to do a base64 encode/decode is the use the built-in features of Ruby.
> The Array class has a pack method..." and it doesn't mention the
> base64 class; so I didn't look for one.

Its got good advice, thats an odd-ball header, and I wouldn't actually
use it, but it saved me typing example code...

Cheers,
Sam



simple_language@yahoo.com

1/22/2008 9:56:00 AM

0

chakkouri.a...@gmail.com wrote:

> you want to prove that koran is not true,
> i will show you an easy way to do that
> what do you say?

I am not trying to prove that I am smarter than you are. I just want
to exchange information about Islam, especially the Koran. I have been
critical about Islam, but this does not mean that I am your enemy. I
am a Westerner, so I am used to debating and disagreeing with friends.
Westerners do not kill each other just because they disagree about
something.

I am not saying that the Koran is completely false, but I believe that
the Koran, like all other holly books, has flaws. You are not going to
learn about these flaws from the Islamic scholars, because there is a
custom of killing Islamic scholars who make such claims. My main
argument is that Muslims should be free to debate their religion
without fear of being killed for doing so. If Muslims gain this right,
they will become Westerners, and they will cease killing each other
and the infidels. Muslims are violent because they do not know the
truth and because they try to kill everyone who is telling them the
truth.

Here are the best books about Islam; they are written by a former
Muslim scholar who became an apostate:
"Why I Am Not A Muslim" (http://tinyurl....), "Leaving
Islam" (http://tinyurl....) by Ibn Warraq,

This is probably the best forum for open minded Muslims:
http://formermuslims....