in reply to Re^2: URL string compression?
in thread URL string compression?
use MIME::Base64; sub encode { my ($compressed) = @_; my $encoded = encode_base64($compressed); $encoded =~ s{\+}{-}g; $encoded =~ s{\/}{_}g; return $encoded; } sub decode { my ($encoded) = @_; $encoded =~ s{-}{+}g; $encoded =~ s{_}{/}g; my $compressed = decode_base64($encoded); return $compressed; }
Update: On second thought, if people are gong to save these files on their own PCs, you'll need to be case-insensitive. That leaves 38 safe characters. If you wrote Base32 based on Base64 (a simple task), you'll have to compress the data down to 28 bytes (floor((90/2) * (log2(32)/8))).
Update: Fixed attrocious math.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: URL string compression?
by punch_card_don (Curate) on Feb 13, 2006 at 23:52 UTC | |
by ikegami (Patriarch) on Feb 13, 2006 at 23:58 UTC | |
by punch_card_don (Curate) on Feb 14, 2006 at 00:42 UTC | |
by ikegami (Patriarch) on Feb 14, 2006 at 01:16 UTC | |
by BrowserUk (Patriarch) on Feb 14, 2006 at 02:50 UTC | |
| |
by blahblahblah (Priest) on Feb 14, 2006 at 02:59 UTC |