O_EXCL
, which guarantees that
the file did not exist before this call. The directory for temporary
files is defined by the Prolog flag tmp_dir.
The following options are processed:
binary
opens the file in binary mode.This predicate is a safe replacement of tmp_file/2. Note that in those cases where the temporary file is needed to store output from an external command, the file must be closed first. E.g., the following downloads a file from a URL to a temporary file and opens the file for reading (on Unix systems you can delete the file for cleanup after opening it for reading):
open_url(URL, In) :- tmp_file_stream(text, File, Stream), close(Stream), process_create(curl, ['-o', File, URL], []), open(File, read, In), delete_file(File). % Unix-only
Temporary files created using this call are removed if the Prolog process terminates gracefully. Calling delete_file/1 using FileName removes the file and removes the entry from the administration of files-to-be-deleted.