Posted to tcl by aspect at Fri Jan 06 00:52:55 GMT 2017view raw
- #!/usr/bin/env tclsh
- #
- package require zlib
- set algos {
- "compress 9" decompress
- "deflate 9" inflate
- "gzip -level 9" gunzip
- }
- set output [read stdin]
- set sizes [dict map {c _} $algos {
- string length [zlib {*}[linsert $c 1 $output]]
- }]
- set sizes [lsort -stride 2 -index 1 -integer $sizes]
- set c [lindex $sizes 0]
- set d [dict get $algos $c]
- set b64cstr [binary encode base64 [zlib {*}[linsert $c 1 $output]]]
- set pgm "package require zlib\n"
- append pgm "puts \[zlib $d \[binary decode base64 [list $b64cstr]\]\]"
- puts "# [string length $pgm] bytes (excluding final newline):"
- puts $pgm
- # output for the old lady:
- # # 384 bytes (excluding final newline):
- # package require zlib
- # puts [zlib inflate [binary decode base64 5ZCxTsQwEET7fMV016B8B3RIRKLey/psg/Ge7Jys/D3ei0+5oBRUCERn7T7PzszgTDIolEEREhiBeEZxglwoBCmGQTiFuQe6J7DEw4T3KKUyM7Izd9zkaFL0oaLPJjk6ZyUOIYC96btu+NaxfPZskooMKliStzboJjLunm/t7WOuPKq0Wnz54sg0OUyCkabRXWfN5M/kOfrEKvFYj9AxXxKrmUa0/b513WyNr938wqD17PXYB1kfzaK6SVqB/aDjQq6+b539+U5YrCq8qhrBid02Utf7jfBCrq5buf+pOycpm5u3+pEhJ4xyqdO++wQ=]]