wxfilesystem
the wxhtml library uses a virtual file systems mechanism
similar to the one used in midnight commander, dos navigator,
far or almost any modern file manager. it allows the user to access
data stored in archives as if they were ordinary files. on-the-fly
generated files that exist only in memory are also supported.
classes
three classes are used in order to provide virtual file systems mechanism:
- the wxfsfile class provides information
about opened file (name, input stream, mime type and anchor).
- the wxfilesystem class is the interface.
its main methods are changepathto() and openfile(). this class
is most often used by the end user.
- the wxfilesystemhandler is the core
of virtual file systems mechanism. you can derive your own handler and pass it to
the vfs mechanism. you can derive your own handler and pass it to
wxfilesystem's addhandler() method. in the new handler you only need to
override the openfile() and canopen() methods.
locations
locations (aka filenames aka addresses) are constructed from four parts:
- protocol - handler can recognize if it is able to open a
file by checking its protocol. examples are "http", "file" or "ftp".
- right location - is the name of file within the protocol.
in "http://www.wxwidgets.org/index.php" the right location is "//www.wxwidgets.org/index.php".
- anchor - an anchor is optional and is usually not present.
in "index.htm#chapter2" the anchor is "chapter2".
- left location - this is usually an empty string.
it is used by 'local' protocols such as zip.
see combined protocols paragraph for details.
combined protocols
the left location precedes the protocol in the url string.
it is not used by global protocols like http but it becomes handy when nesting
protocols - for example you may want to access files in a zip archive:
file:archives/cpp_doc.zip#zip:reference/fopen.htm#syntax
in this example, the protocol is "zip", right location is
"reference/fopen.htm", anchor is "syntax" and left location
is "file:archives/cpp_doc.zip".
there are two protocols used in this example: "zip" and "file".
file systems included in wxhtml
the following virtual file system handlers are part of wxwidgets so far:
wxarchivefshandler
|
a handler for archives such as zip
and tar. include file is <wx/fs_arc.h>. urls examples:
"archive.zip#zip:filename", "archive.tar.gz#gzip:#tar:filename".
|
wxfilterfshandler
|
a handler for compression schemes such
as gzip. header is <wx/fs_filter.h>. urls are in the form, e.g.:
"document.ps.gz#gzip:".
|
wxinternetfshandler
|
a handler for accessing documents
via http or ftp protocols. include file is <wx/fs_inet.h>.
|
wxmemoryfshandler
|
this handler allows you to access
data stored in memory (such as bitmaps) as if they were regular files.
see wxmemoryfshandler documentation for details.
include file is <wx/fs_mem.h>. url is prefixed with memory:, e.g.
"memory:myfile.htm"
|
in addition, wxfilesystem itself can access local files.
initializing file system handlers
use wxfilesystem::addhandler to initialize
a handler, for example:
#include <wx/fs_mem.h>
...
bool myapp::oninit()
{
wxfilesystem::addhandler(new wxmemoryfshandler);
...
}
|