egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

zlib tclsh8.6

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Ofloo
Owner


Joined: 13 May 2003
Posts: 953
Location: Belguim

PostPosted: Mon Aug 15, 2011 7:54 am    Post subject: zlib tclsh8.6 Reply with quote

how do i decompress gzip file from url
Code:


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]]}


this errors
_________________
XplaiN but think of me as stupid
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Aug 15, 2011 9:25 am    Post subject: Reply with quote

Well, posting the actual error message is usually helpful..

That said, you've enclosed your "set" command within brackets, and then pass the output to "catch" for evaluation. Unless you were intending to execute the whole text on the webpage as a single tcl-command, this is probably your problem. Even if this is what you intended, be adviced that the text received is used explicitly as the command; you will not be able to pass arguments this way.

I'd also recommend using the error/result-variable option with catch, so that you can actually see the error you're trying to catch...

All in all, I'd probably re-write that piece something like this:
Code:
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


}

Be adviced, I've intentionally left out the set command within the catch argument, as it is not needed.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Ofloo
Owner


Joined: 13 May 2003
Posts: 953
Location: Belguim

PostPosted: Mon Aug 15, 2011 10:20 am    Post subject: Reply with quote

Quote:
$ ./zlib_test.tcl
An error occured while fetching http://: corrupted input data
$ gunzip /tmp/file.gz
$ ls /tmp/file
/tmp/file
$


Code:
#!/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"
}


EDIT

an other thing i noticed is that when you use tcl 8.6 that you're not supposed to add package require zlib

Code:
#!/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
}


otherwise it will not have the option zlib gunzip however the result is exactly the same though. And an other surprise it did a decompression. However this is a test file, .. and the link i'm getting doesn't contain the file name which results back into the same error.
_________________
XplaiN but think of me as stupid
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber