Version 5 of Chuck Ferril

Updated 2004-06-22 07:18:02

aka: wcf3

Email: chuck at ferril dot com

My Tcl stuff page: http://wcferril.home.mchsi.com/ (including tDOM for Linux, FreeBSD, Solaris-Sparc, Solaris-x86, Mac OSX, and Windows)


Here is my one-line fix for using vfs to read OpenOffice/StarOffice document files. I could never get anyone to merge this into the source tree (or even respond)...perhaps it was fixed in another way, but I never heard about it... anyway here is the complete zip::Data procedure from zipvfs.tcl with my change buried within the massive comment:

 proc zip::Data {fd arr {varPtr ""} {verify 0}} {
    upvar 1 $arr sb

    if { $varPtr != "" } {
        upvar 1 $varPtr data
    }

    set buf [read $fd 30]
    set n [binary scan $buf A4sssssiiiss \
                hdr sb(ver) sb(flags) sb(method) \
                time date \
                sb(crc) sb(csize) sb(size) flen elen]

    if { ![string equal "PK\03\04" $hdr] } {
        binary scan $hdr H* x
        error "bad header: $x"
    }
    set sb(ver)                [u_short $sb(ver)]
    set sb(flags)        [u_short $sb(flags)]
    set sb(method)        [u_short $sb(method)]
    set sb(mtime)        [DosTime $date $time]

    set sb(name) [read $fd [u_short $flen]]
    set sb(extra) [read $fd [u_short $elen]]

    if { $varPtr == "" } {
        seek $fd $sb(csize) current
    } else {
 #!!! Added by Chuck Ferril 10-26-03 to fix reading of OpenOffice
 #!!!  .sxw files. Any files in the zip that had a method of 8
 #!!!  (deflate) failed here because size and csize were zero.
 #!!!  I'm not sure why the above computes the size and csize
 #!!!  wrong, but stat appears works properly. I originally
 #!!!  checked for csize of zero, but adding this change didn't
 #!!!  appear to break the non-deflated file access and seemed
 #!!!  more natural.
        zip::stat $fd $sb(name) sb
 #!!! End of my change
        set data [read $fd $sb(csize)]
    }

    if { $sb(flags) & 0x4 } {
        # Data Descriptor used
        set buf [read $fd 12]
        binary scan $buf iii sb(crc) sb(csize) sb(size)
    }


    if { $varPtr == "" } {
        return ""
    }

    if { $sb(method) != 0 } {
        if { [catch {
            set data [vfs::zip -mode decompress -nowrap 1 $data]
        } err] } {
            ::vfs::log "$sb(name): inflate error: $err"
            binary scan $data H* x
            ::vfs::log $x
        }
    }
    return
    if { $verify } {
        set ncrc [vfs::crc $data]
        if { $ncrc != $sb(crc) } {
            tclLog [format {%s: crc mismatch: expected 0x%x, got 0x%x} \
                    $sb(name) $sb(crc) $ncrc]
        }
    }
 }

[ Category Person | Category Home Page ]