A.22 library(iostream): Utilities to deal with streams
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(iostream): Utilities to deal with streams
          • open_any/5
          • close_any/1
          • open_hook/6
    • Packages
Availability::- use_module(library(iostream)).(can be autoloaded)
Sourceopen_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:
encoding(Enc)
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 file(Specification).

Stream
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.
stream(Stream)
Same as a plain Stream.
FileURL
If Specification is of the form =file://...=, the pointed to file is opened using open/4. Requires library(uri) to be installed.
file(Path)
Explicitly open the file Path. Path can be an Path(File) term as accepted by absolute_file_name/3.
string(String)
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.

setup_call_cleanup(
    open_any(Spec, read, In, Close, Options),
    <process>(In),
    Close).

Currently, the following libraries extend this predicate:

library(http/http_open)
Adds support for URLs using the http and https schemes.