Version 3 of tclVFS examples

Updated 2004-10-29 12:59:50 by lwv

lv Question: can anyone provide an example of how one could use the vfs package to poke around a gzipped tar file?


Take a look at the One-line web browser in Tcl for an example of things that can be done.


Using the tclvfs extension, you can now do things like this

    package require vfs::urltype
    vfs::urltype::Mount ftp
    file copy ftp://foo.bar.com/pub/Readme .
    file copy ftp://user:[email protected]/private.txt .

or

    package require vfs::ftp
    vfs::urltype::Mount ftp
    set image [image create photo -file ftp://ftp.ucsd.edu/pub/alpha/tcl/alphatk/alphatk.gif]
    pack [label .b -image $image]

or

    package require vfs::zip
    vfs::zip::Mount foo.zip foo.zip
    cd foo.zip ; glob *

or

    package require vfs::urltype
    vfs::urltype::Mount ftp
    set listing [glob -dir ftp://ftp.scriptics.com/pub *]

or

    package require vfs::urltype
    vfs::urltype::Mount http
    set fd [open http://sourceforge.net/projects/tcl]
    set contents [read $fd] ; close $fd

or nested mounts:

    package require vfs::ftp
    package require vfs::zip
    vfs::ftp::Mount ftp://ftp.ucsd.edu/pub pub
    vfs::zip::Mount pub/archive.zip pub/archive.zip
    % load a .dll from inside a .zip which sits on a remote ftp site.
    load pub/archive.zip/foo.dll

(Caveat: I haven't actually tried this last one....)

Notice that you need to Mount non-native filesystems before you can use them. There are two kinds of mounts that tclvfs supports. The first kind is a particular mount point such as an archive 'foo.zip' or 'ftp://ftp.scriptics/com/pub ' which can be mapped onto any point in the local filesystem. The contents of those mounts (i.e. the contents of the zip archive or the contents of the remote ftp site) are then accessible as normal, local files.

The second kind of mount is a 'protocol' (somewhat clumsily called a 'urltype' in the current vfs library), which is illustrated in 3 of the examples above. Here we are effectively creating a new drive called 'ftp:// ' or 'http:// ', and any access within that drive causes the tclvfs library to attempt to perform a mount of the first kind so that the contents can be accessed.


Category VFS