From: Wesley J Landaker Date: 2004-01-07T10:37:17+09:00 Subject: Re: Compression (besides Huffman) and Ruby --Boundary-02=_AL2+/FjRAtxYqwa Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Description: signed data Content-Disposition: inline On Tuesday 06 January 2004 6:06 pm, Josef 'Jupp' SCHUGT wrote: > Hi! > > I don't want to start a lenghty thread about wether that makes sense > or not. My question is only if such a thing is known to exist. I did > find Huffman but besides that rei, nada, rien, zero, nichts. Anything > else (note that the point is *plain* Ruby, no extension). Otherwise I > will try to implement such an algorithm on my own. Well, here's a really bad RLE encoder/decoder. ;) #!/usr/bin/ruby $last=3Dnil $count=3D0 def compress while gets $_.each_byte { |c| if c =3D=3D $last $count +=3D 1 else puts "#{$count}:#{$last}"; $last =3D c $count =3D 1 end } end end def decompress while gets ~ /(\d+):(\d+)/ $1.to_i.times { s =3D ' '; s[0] =3D $2.to_i; print s } end end if ARGV.shift =3D=3D '-d' decompress else compress end Usually I just do: require 'zlib' Since it comes with ruby. =3D) =2D-=20 Wesley J. Landaker - wjl@icecavern.net OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2 --Boundary-02=_AL2+/FjRAtxYqwa Content-Type: application/pgp-signature Content-Description: signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQA/+2LA8KmKTEzW49IRAkvKAJ9O7L6KUfvNQCq3KpwLCOyDMO2wpgCeKIE5 XOeeqH1C0dMPlNDY2yNTVic= =trBq -----END PGP SIGNATURE----- --Boundary-02=_AL2+/FjRAtxYqwa--