4.17.5 Adding IRI schemas
The file handling predicates may be hooked to deal with
IRIs. An IRI starts with <scheme>://
,
where <scheme> is a non-empty sequence of lowercase
ASCII letters. After detecting the scheme the file manipulation
predicates call a hook that is registered using register_iri_scheme/3.
Hooking the file operations using extensible IRI schemas allows us to place any resource that is accessed through Prolog I/O predicates on arbitrary devices such as web servers or the ZIP archive used to store program resources (see section 13.2). This is typically combined with file_search_path/2 declarations to switch between accessing a set of resources from local files, from the program resource database, from a web-server, etc.
- register_iri_scheme(+Scheme, :Hook, +Options)
- Register Hook to be called by all file handling predicates if
a name that starts with Scheme:// is encountered. The
Hook is called by call/4
using the operation, the
IRI and a term that receives the result of the
operation. The following operations are defined:
- open(Mode,Options)
- Called by open/3,4. The result argument must be unified with a stream.
- access(Mode)
- Called by access_file/2, exists_file/1
(Mode is
file
) and exists_directory/1 (Mode isdirectory
). The result argument must be unified with a boolean. - time
- Called by time_file/2. The result must be unified with a time stamp.
- size
- Called by size_file/2. The result must be unified with an integer representing the size in bytes.