- Reference manual
- SWI-Prolog C-library
- library(process): Create processes and redirect I/O
- library(filesex): Extended operations on files
- library(uid): User and group management on Unix systems
- library(syslog): Unix syslog interface
- library(socket): Network socket (TCP and UDP) library
- The stream_pool library
- library(uri): Process URIs
- CGI Support library
- Password encryption library
- library(uuid): Universally Unique Identifier (UUID) Library
- SHA* Secure Hash Algorithms
- library(md5): MD5 hashes
- library(hash_stream): Maintain a hash on a stream
- Memory files
- Time and alarm library
- library(unix): Unix specific operations
- Limiting process resources
- library(udp_broadcast): A UDP Broadcast Bridge
- library(prolog_stream): A stream with Prolog callbacks
- SWI-Prolog C-library
library(memfile) provides an alternative to
temporary files, intended for temporary buffering of data. Memory files
in general are faster than temporary files and do not suffer from
security risks or naming conflicts associated with temporary-file
There is no limit to the number of memory streams, nor the size of them. However, a single memory file cannot have multiple streams at the same time, i.e., a memory file cannot be opened multiple times, not even for reading. Memory files are thread-safe and subject to (atom) garbage collection.
- Create a new memory file and return a unique opaque handle to it.
- Discard the memory file and its contents. If the file is open it is first closed.
- open_memory_file(+Handle, +Mode, -Stream)
- Open the memory-file. Mode is one of
insert. The resulting Stream must be closed using close/1. When opened for
insert, the current location is initialized at the start of the data and can be modified using seek/2 or set_stream_position/2. In
updatemode, existing content is replaced, while the size is enlarged after hitting the end of the data. In
insertmode, the new data is inserted at the current point.
- open_memory_file(+Handle, +Mode, -Stream, +Options)
- Open a memory-file as open_memory_file/3.
- Set the encoding for a memory file and the created stream. Encoding
names are the same as used with open/4.
By default, memoryfiles represent UTF-8 streams, making them capable of
storing arbitrary Unicode text. In practice the only alternative is
octet, turning the memoryfile into binary mode. Please study SWI-Prolog Unicode and encoding issues before using this option.
falseand the memory file is opened for reading, discard the file (see free_memory_file/1) if the input is closed. This is used to realise open_chars_stream/2 in library(charsio).
- size_memory_file(+Handle, -Size)
- Return the content-length of the memory-file in characters in the current encoding of the memory file. The file should be closed and contain data.
- size_memory_file(+Handle, -Size, +Encoding)
- Return the content-length of the memory-file it characters in the given Encoding. The file should be closed and contain data.
- atom_to_memory_file(+Atom, -Handle)
- Turn an atom into a read-only memory-file containing the (shared)
characters of the atom. Opening this memory-file in mode
writeyields a permission error.
- insert_memory_file(+Handle, +Offset, +Data)
- Insert Data into the memory file at location Offset. The offset is specified in characters. Data can be an atom, string, code or character list. Other terms are first serialized using writeq/1. This predicate raises a domain_error exception if Offset is out of range and a permission_error if the memory file is read-only or opened.
- delete_memory_file(+Handle, +Offset, +Length)
- Delete a Length characters from the memory file, starting at Offset. This predicate raises a domain_error exception if Offset or Offset+Length is out of range and a permission_error if the memory file is read-only or opened.
- memory_file_to_atom(+Handle, -Atom)
- Return the content of the memory-file in Atom.
- memory_file_to_atom(+Handle, -Atom, +Encoding)
- Return the content of the memory-file in Atom, pretending the
data is in the given Encoding. This can be used to convert
from one encoding into another, typically from/to bytes. For example, if
we must convert a set of bytes that contain text in UTF-8, open the
memory file as octet stream, fill it, and get the result using Encoding
- memory_file_to_codes(+Handle, -Codes)
- Return the content of the memory-file as a list of character-codes in Codes.
- memory_file_to_codes(+Handle, -Codes, +Encoding)
- Return the content of the memory-file as a list of character-codes in Codes, pretending the data is in the given Encoding.
- memory_file_to_string(+Handle, -String)
- Return the content of the memory-file as a string in -String.
- memory_file_to_string(+Handle, -String, +Encoding)
- Return the content of the memory-file as a string in String, pretending the data is in the given Encoding.
- memory_file_substring(+Handle, ?Before, ?Length, ?After, -SubString)
- SubString is a substring of the memory file. There are Before characters in the memory file before SubString, SubString contains Length character and is followed by After characters in the memory file. The signature is the same as sub_string/5 and sub_atom/5, but currently at least two of the 3 position arguments must be specified. Future versions might implement the full functionality of sub_string/5.
- memory_file_line_position(+MF, ?Line, ?LinePos, ?Offset)
- True if the character offset Offset corresponds with the LinePos character on line Line. Lines are counted from one (1). Note that LinePos is not the column as each character counts for one, including backspace and tab.