From: "Brian K. White" <brian@aljex.com>
To: <zsh-users@sunsite.dk>
Subject: Re: base64 coding for zsh ?
Date: Wed, 13 Sep 2006 20:21:47 -0400 [thread overview]
Message-ID: <03ba01c6d793$d3bd7110$6500000a@venti> (raw)
In-Reply-To: <20060913150818.GA9450@ulpmm.u-strasbg.fr>
----- Original Message -----
From: "Marc Chantreux" <marc.chantreux@ulpmm.u-strasbg.fr>
To: "zsh-users" <zsh-users@sunsite.dk>
Sent: Wednesday, September 13, 2006 11:08 AM
Subject: Re: base64 coding for zsh ?
le 12/09/2006,
Bart Schaefer nous crivait :
> It's about 50 lines of readably-formatted C code to write a base64
> decoder,
so i'll write my first zsh module. It's added to my todo list.
> slightly more than that to write the encoder, not counting the
> lookup tables. It could be done in shell script, but it would be very
> slow and probably not worth the effort.
ok, i give this solution away.
> alias enB64="perl -MMIME::Base64 -e 'print encode_base64(shift @ARGV)'"
> alias deB64="perl -MMIME::Base64 -e 'print decode_base64(shift @ARGV)'"
well ... i think perl is quite huge for this problem. I'll use openssl
as temporary hack.
alias B64enc='openssl base64'
alias B64dec='openssl base64 -d'
thanks for help.
regards.
------------
I've been using the stand-alone:
http://www.fourmilab.ch/webtools/base64/
I never realised I already had it in openssl.
Thanks for the tip.
This led me to see what else I might already have or could get in a ready
made package rather than having to use a source.
(I do need this util in some form on every box and previously all my boxes
were SCO OpenServer and I had been using the fourmilab source for years.)
Then I decided to run a few simple time tests, since this gets used a lot in
various system() commands in application code and cgi scripts etc...
I expected the simple plain base64 util to be the fastest but I was wrong:
In each case I repeated the same command many times and always got almost
exactly the same results, that is, +- 0m0.004 of the numbers shown so these
are representative not just a fluke or caching effects or effects of the os
being busy elsewhere.
the fourmilab source:
nj4:~ # time base64 </boot/vmlinuz >/dev/null
real 0m0.074s
user 0m0.072s
sys 0m0.000s
openssl:
nj4:~ # time opsnssl base64 </boot/vmlinuz >/dev/null
-bash: opsnssl: command not found
real 0m0.001s
user 0m0.000s
sys 0m0.000s
mimencode comes in the metamail package:
nj4:~ # time mimencode </boot/vmlinuz >/dev/null
real 0m0.078s
user 0m0.076s
sys 0m0.004s
gmime-uuencode:
It actually does base64 not uuencode if you give it the -m or --base64
option.
It comes in the gmime package.
It prepends and appends some junk to the actual base64 output so it's
inconvenient for me to actually use:
nj4:~ # echo this is a test |gmime-uuencode -m -
begin-base64 600 -
dGhpcyBpcyBhIHRlc3QK
====
nj4:~ #
As for the speed:
nj4:~ # time gmime-uuencode -m - </boot/vmlinuz >/dev/null
real 0m0.009s
user 0m0.008s
sys 0m0.000s
Ooenssl destroys the rest.
So even though I have the dedicated util it's actually better to use
openssl.
As a side benefit, thats one less special thing to maintain on all my boxes.
On a related note. I had/have a need for a standalone url encoder/decoder
and made one myself, then receive the help of someone else to make it into a
proper util with man page and getopts() and basic sanity checking etc... The
source is here. I never bothered to make linux binaries except for myself
yet but it's such basic code it builds with no problems anywhere.
http://www.aljex.com/bkw/sco/#urldec
Does anyone know of an already existing util to do that?
I can't imagine how something so basic can be made 78 times faster but I
would have said the same thing about base64 until now also.
Note: I'd like it to work as a filter like cat, like all the utils above.
In fact, my util has options to do both, work as a filter or take a string
on the command line.
Thanks.
btw, compared to above, ick...
nj4:~ # time urlenc </boot/vmlinuz >/dev/null
real 0m0.332s
user 0m0.332s
sys 0m0.000s
Brian K. White -- brian@aljex.com -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
next prev parent reply other threads:[~2006-09-14 0:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-12 15:08 Marc Chantreux
2006-09-13 1:27 ` Bart Schaefer
2006-09-13 15:08 ` Marc Chantreux
2006-09-14 0:21 ` Brian K. White [this message]
[not found] ` <20060914003316.GD8475@lorien.comfychair.org>
2006-09-14 4:05 ` Brian K. White
2006-09-14 14:50 ` Marc Chantreux
2006-09-14 15:49 ` Bart Schaefer
2006-09-15 1:49 ` Brian K. White
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='03ba01c6d793$d3bd7110$6500000a@venti' \
--to=brian@aljex.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).