From: Pat Thoyts Date: Mon, 22 Dec 2008 01:19:34 +0000 (+0000) Subject: Fix vfs::ztream to support 8.6 core zlib X-Git-Url: http://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=30e00ae711eb0b75a606cd06841094fa0356f385;p=tclvfs Fix vfs::ztream to support 8.6 core zlib --- diff --git a/ChangeLog b/ChangeLog index 634d097..3bbf1c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-22 Pat Thoyts + + * library/mk4vfs.tcl: Fix vfs::ztream to support 8.6 core zlib + * library/vfslib.tcl: + 2008-12-12 Pat Thoyts * library/zipvfs.tcl: Cleaned up the zip stream read function to diff --git a/library/mk4vfs.tcl b/library/mk4vfs.tcl index 8e7bbcf..0ac16db 100644 --- a/library/mk4vfs.tcl +++ b/library/mk4vfs.tcl @@ -168,7 +168,6 @@ namespace eval vfs::mk4 { 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] diff --git a/library/vfslib.tcl b/library/vfslib.tcl index 6340803..64f2939 100644 --- a/library/vfslib.tcl +++ b/library/vfslib.tcl @@ -132,13 +132,33 @@ if {[info command rechan] != "" || ![catch {load "" rechan}]} { } variable ::vfs::zseq 0 ;# used to generate temp zstream cmd names - proc vfs::zstream {mode ifd clen ilen} { - set cname _zstream_[incr ::vfs::zseq] - zlib s$mode $cname - set cmd [list ::vfs::zstream_handler $cname $ifd $clen $ilen s$mode] - set fd [rechan $cmd 2] - set ::vfs::_zstream_pos($fd) 0 - return $fd + + # vfs::zstream -- + # wrapper to manage a stacked zlib channel. If we have the core + # zlib implementation then make use of that. Otherwise we can use + # rechan and the tclkit zlib package to do the same thing. + # + # mode - compress or decompress + # ifd - input channel (should be binary) + # clen - size of compressed data in bytes + # ilen - size of decompressed data in bytes + # Result: + # A stacked channel then handles compression for us. + # + if {[package vsatisfies [package provide Tcl] 8.6]} { + proc vfs::zstream {mode ifd clen ilen} { + return [zlib push $mode $ifd] + } + } else { + proc vfs::zstream {mode ifd clen ilen} { + set cname _zstream_[incr ::vfs::zseq] + zlib s$mode $cname + fconfigure $fd -translation binary + set cmd [list ::vfs::zstream_handler $cname $ifd $clen $ilen s$mode] + set fd [rechan $cmd 2] + set ::vfs::_zstream_pos($fd) 0 + return $fd + } } }