This library contains utilities that deal with streams, notably
originating from non-built-in sources such as URLs, archives, windows,
The predicate open_any/5 acts as a broker between applications that
can process data from a stream and libraries that can create streams
from diverse sources. Without this predicate, processing data inevitally
follows the pattern below. As call_some_open_variation can be
anything, this blocks us from writing predicates such as
DOM) that can operate on arbitrary input sources.
Libraries that can open streams can install the hook
iostream:open_hook/6 to make their functionality available through
- See also
- - library(archive), library(process), library(zlib),
- open_any(+Specification, +Mode, -Stream, -Close, +Options)
- Establish a stream from Specification that should be closed
using Close, which can either be called or passed to
close_any/1. Options processed:
- Set stream to encoding Enc.
Without loaded plugins, the open_any/5 processes the following
values for Specification. If no rule matches, open_any/5
processes Specification as
- A plain stream handle. Possisible post-processing options such
as encoding are applied. Close does not close the stream,
but resets other side-effects such as the encoding.
- Same as a plain Stream.
- If Specification is of the form =file://...=, the pointed
to file is opened using open/4. Requires library(uri) to
- Explicitly open the file Path. Path can be an Path(File)
term as accepted by absolute_file_name/3.
- Open a Prolog string, atom, list of characters or codes
as an input stream.
The typical usage scenario is given in the code below, where
<process> processes the input.
open_any(Spec, read, In, Close, Options),
Currently, the following libraries extend this predicate:
- Adds support for URLs using the
- input_options(+Stream0, -Stream, +Close0, -Close, +Options) is det[private]
- Establish the final stream.
- open_any_builtin(+Spec, +Mode, -Stream, -Close, +Options0, -Options) is semidet[private]
- Built-in open-any operations
- Execute the Close closure returned by open_any/5. The closure
can also be called directly. Using close_any/1 can be considered
better style and enhances tractability of the source code.
- open_hook(+Spec, +Mode, -Stream, -Close, +Options0, -Options) is semidet[multifile]
- Open Spec in Mode, producing Stream.
|Close||- is unified to a goal that must be called to undo the
side-effects of the action, e.g., typically the term |
|Options0||- are the options passed to open_any/5|
|Options||- are passed to the post processing filters that
may be installed by open_any/5.|