Changeset 647 for trunk/tcl/scripts


Ignore:
Timestamp:
Mar 28, 2007, 2:16:50 PM (18 years ago)
Author:
dkearney
Message:

added -type and -compress flags to put function so users can now
provide put function with a ffile name and -type file flag and
tcl rappture will upload the file and place the text into the xml
automatically. with the -compress flag, users can have the text
they are put'ing gzip compressed and base64 encoded.

also, the get function automatically decodes data that is get'ed
from the xml file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tcl/scripts/library.tcl

    r115 r647  
    447447        return ""
    448448    }
    449     return [string trim [$node text]]
    450 }
    451 
    452 # ----------------------------------------------------------------------
    453 # USAGE: put ?-append yes? ?-id num? ?<path>? <string>
     449    return [string trim [Rappture::encoding::decode [$node text]]]
     450}
     451
     452# ----------------------------------------------------------------------
     453# USAGE: put ?-append yes? ?-id num? ?-type string|file? ?-compress no? ?<path>? <string>
    454454#
    455455# Clients use this to set the value of a node.  If the path is not
     
    469469        -id ""
    470470        -append no
     471        -type string
     472        -compress no
    471473    }
    472474    while {[llength $args] > 1} {
     
    484486    }
    485487    if {[llength $args] > 2} {
    486         error "wrong # args: should be \"put ?-append bval? ?-id num? ?path? string\""
     488        error "wrong # args: should be \"put ?-append bval? ?-id num? ?-type string|file? ?-compress bval? ?path? string\""
    487489    }
    488490    if {[llength $args] == 2} {
     
    493495        set str [lindex $args 0]
    494496    }
     497
     498    if {$params(-type) == "file"} {
     499        set fileName $str
     500        set fid [open $fileName r]
     501        fconfigure $fid -translation binary
     502        set str [read $fid]
     503        close $fid
     504    }
     505
     506    if {$params(-compress) || [Rappture::encoding::is binary $str]} {
     507        set str [Rappture::encoding::encode $str]
     508    }
     509
    495510    set node [find -create $path]
    496511
Note: See TracChangeset for help on using the changeset viewer.