Version 10 of tclVFS examples

Updated 2015-06-23 22:42:20 by Sven

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
    set mnt_file [vfs::zip::Mount foo.zip foo.zip]
    cd foo.zip ; glob *
    cd ..
    vfs::zip::Unmount $mnt_file foo.zip

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

    package require vfs::ns
    vfs::ns::Mount :: ::
    cd ::
    set f [open "unknown" r]
    set proc_definition [read $f]
    close $f

(Caveat: there's a bug in the 0.5 version of the namespace driver that causes glob to return names with the first character missing. cd/open/read seem to work ok though)

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....) MHo: But exec won't work, right?

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.


Moritz: How can I simply treat a normal local file as filesystem?

What exactly do you mean by that? If the "normal local file" is a zip file, starkit or tar file, for example, mount it like one of the examples above. If it's a plain text file or some other format you will have to create a vfs driver for it.