Code: Select all
package require http
package require zlib
set url "http://"
set tok [http::geturl $url -binary 1]
set dat [http::data $tok]
http::cleanup $tok
catch {[set dcd [zlib decompress $dat]]}
Code: Select all
package require http
package require zlib
set url "http://"
set tok [http::geturl $url -binary 1]
set dat [http::data $tok]
http::cleanup $tok
catch {[set dcd [zlib decompress $dat]]}
Code: Select all
package require http
package require zlib
set url "http://"
set tok [http::geturl $url -binary 1]
set dat [http::data $tok]
http::cleanup $tok
if {[catch {zlib decompress $dat} dcd]} {
#Something went wrong, the error message is available in dcd
putlog "An error occured while fetching $url: $dcd"
} else {
#Everything went smoothly.. do whatever you need with the data in dcd
#Should you desire to execute the content of $dcd as a valid tcl command line, uncommend the following line:
#catch {eval $dcd} result
}
$ ./zlib_test.tcl
An error occured while fetching http://: corrupted input data
$ gunzip /tmp/file.gz
$ ls /tmp/file
/tmp/file
$
Code: Select all
#!/usr/local/bin/tclsh8.6
package require http
package require zlib
set url {http://}
set tok [http::geturl $url -binary 1]
set dat [http::data $tok]
http::cleanup $tok
if {![catch {open /tmp/file.gz w} w]} {
fconfigure $w -translation binary -encoding binary
puts -nonewline $w $dat
close $w
}
if {[catch {zlib decompress $dat} dcd]} {
puts "An error occured while fetching $url: $dcd"
}
Code: Select all
#!/usr/local/bin/tclsh8.6
package require http
set url {http://narf.ofloo.net/file.gz}
set tok [http::geturl $url -binary 1]
set dat [http::data $tok]
http::cleanup $tok
if {![catch {open /tmp/file.gz w} w]} {
fconfigure $w -translation binary -encoding binary
puts -nonewline $w $dat
close $w
}