Posted to tcl by jdc at Tue Sep 28 07:38:35 GMT 2010view raw

  1. proc open {db file mode permissions} {
  2. # return a list of two elements:
  3. # 1. first element is the Tcl channel name which has been opened
  4. # 2. second element (optional) is a command to evaluate when
  5. # the channel is closed.
  6. switch -glob -- $mode {
  7. {} -
  8. r {
  9. ::mk4vfs::stat $db $file sb
  10.  
  11. if { $sb(csize) != $sb(size) } {
  12. if {$::mk4vfs::zstreamed} {
  13. set fd [mk::channel $sb(ino) contents r]
  14. fconfigure $fd -translation binary
  15. set fd [vfs::zstream decompress $fd $sb(csize) $sb(size)]
  16. } else {
  17. set fd [vfs::memchan]
  18. fconfigure $fd -translation binary
  19. set s [mk::get $sb(ino) contents]
  20. puts -nonewline $fd [vfs::zip -mode decompress $s]
  21.  
  22. fconfigure $fd -translation auto
  23. seek $fd 0
  24. }
  25. } elseif { $::mk4vfs::direct } {
  26. set fd [vfs::memchan]
  27. fconfigure $fd -translation binary
  28. puts -nonewline $fd [mk::get $sb(ino) contents]
  29.  
  30. fconfigure $fd -translation auto
  31. seek $fd 0
  32. } else {
  33. set fd [mk::channel $sb(ino) contents r]
  34. }
  35. return [list $fd]
  36. }