]> Sergey Matveev's repositories - paster.git/blobdiff - contrib/paster.tcl
Netstrings are simpler than bencode
[paster.git] / contrib / paster.tcl
index 7ef8f0b159b03064c3389b34c33124aa9d560d4a..ad7c4eff984fa1d5e9b8f6d26dcca44d1670ab31 100755 (executable)
@@ -4,10 +4,11 @@ set Host paster.example.com
 set Port 2021
 set GnuTLS 1
 
+set ext ""
 set fn [lindex $argv 0]
 set size 0
 if {($argc > 0) && [file exists $fn]} {
-    set ext [file extension $fn]
+    set ext [string trimleft [file extension $fn] .]
     set fd [open $fn {RDONLY BINARY}]
     set size [file size $fn]
 } else {
@@ -23,19 +24,16 @@ if $GnuTLS {
     set sock [socket $Host $Port]
     chan configure $sock -encoding binary -translation binary
 }
-puts -nonewline $sock "d"
-if {[info exists ext]} {
-    set ext [string trimleft $ext .]
-    puts -nonewline $sock [string cat "1:e" [string length $ext] ":$ext"]
-}
-puts -nonewline $sock "1:v$size:"
+
+puts -nonewline $sock [string cat [string length $ext] ":$ext,"]
+puts -nonewline $sock "$size:"
 if {[info exists fd]} {
     fcopy $fd $sock
     close $fd
 } {
     puts -nonewline $sock $data
 }
-puts -nonewline $sock "e"
+puts -nonewline $sock ","
 flush $sock
 while {[gets $sock line] >= 0} { puts $line }
 close $sock