Sometimes called [virtual channel] or [stacked channel], not to be confused with [virtual file system]s Tcl 8.5 provides a facility to implement [channel]s (as usually returned by [open] and [socket]) in pure tcl. This enables a library to implement transformations over channels (see [stacked channel]) or present a file-like interface ([read]/[write]/[chan event] etc.) to any data structure. Reflected channels are created with [chan create] and their implementation is documented there, and http://www.tcl.tk/man/tcl8.5/TclCmd/refchan.htm Meanwhile, here's a (sadly untested) implementation of a simple reflected channel which acts as a buffer. namespace eval rchan { variable chan ;# set of known channels array set chan {} proc initialize {chanid} { variable chan set chan($chanid) "" } proc finalize {chanid} { variable chan unset chan($chanid) } variable watching array set watching {read 0 write 0} proc watch {chanid events} { variable watching if {$event eq {}} { foreach event $events { set watching($event) 0 } } else { foreach event $events { set watching($event) 1 } } } proc read {chanid count} { variable contents if {[string length $contents] < $count} { set result $contents; set contents "" } else { set result [string range $contents 0 $count-1] set contents [string range $contents $count end] } # implement max buffering variable watching variable max if {$watching(write) && ([string length $contents] < $max)} { chan postevent $chanid write } return $result } variable max 1048576 ;# maximum size of the reflected channel proc write {chanid data} { variable contents variable max variable watching set left [expr {$max - [string length $contents]}] ;# bytes left in buffer set dsize [string length $data] if {$left >= $dsize} { append contents $data if {$watching(write) && ([string length $contents] < $max)} { # inform the app that it may still write chan postevent $chanid write } } else { set dsize $left append contents [string range $data $left] } # inform the app that there's something to read if {$watching(read) && ($contents ne "")} { chan postevent $chanid read } return $dsize ;# number of bytes actually written } namespace export -clear * namespace ensemble create -subcommands {} }