Posted to tcl by jdc at Tue Sep 28 07:38:35 GMT 2010view raw
- proc open {db file mode permissions} {
- # return a list of two elements:
- # 1. first element is the Tcl channel name which has been opened
- # 2. second element (optional) is a command to evaluate when
- # the channel is closed.
- switch -glob -- $mode {
- {} -
- r {
- ::mk4vfs::stat $db $file sb
-
- if { $sb(csize) != $sb(size) } {
- if {$::mk4vfs::zstreamed} {
- set fd [mk::channel $sb(ino) contents r]
- fconfigure $fd -translation binary
- set fd [vfs::zstream decompress $fd $sb(csize) $sb(size)]
- } else {
- set fd [vfs::memchan]
- fconfigure $fd -translation binary
- set s [mk::get $sb(ino) contents]
- puts -nonewline $fd [vfs::zip -mode decompress $s]
-
- fconfigure $fd -translation auto
- seek $fd 0
- }
- } elseif { $::mk4vfs::direct } {
- set fd [vfs::memchan]
- fconfigure $fd -translation binary
- puts -nonewline $fd [mk::get $sb(ino) contents]
-
- fconfigure $fd -translation auto
- seek $fd 0
- } else {
- set fd [mk::channel $sb(ino) contents r]
- }
- return [list $fd]
- }