temporary-file

API Reference

temporary-file

Temporary file creation library

TEMPORARY-FILE

  • Variable *DEFAULT-TEMPLATE*
    "temporary-files:temp-%"
  • Condition INVALID-TEMPORARY-PATHNAME-TEMPLATE  (ERROR)
  • Condition CANNOT-CREATE-TEMPORARY-FILE  (ERROR)
  • Function OPEN-TEMPORARY (&rest open-arguments &key (template *default-template*) (generate-random-string 'generate-random-string) (max-tries *max-tries*) (direction :output) &allow-other-keys)
    Create a file with a randomly generated name and return the opened stream. The resulting pathname is generated from TEMPLATE, which is a string representing a pathname template. A percent sign (%) in that string is replaced by a randomly generated string to make the filename unique. The default for TEMPLATE places temporary files in the TEMPORARY-FILES logical pathname host, which is automatically set up in a system specific manner. The file name generated from TEMPLATE is merged with *DEFAULT-PATHNAME-DEFAULTS*, so random pathnames relative to that directory can be generated by not specifying a directory in TEMPLATE. GENERATE-RANDOM-STRING can be passed to override the default function that generates the random name component. It should return a random string consisting of characters that are permitted in a pathname (logical or physical, depending on TEMPLATE). The name of the temporary file can be accessed calling the PATHNAME function on STREAM. For convenience, the temporary file is opened on the physical pathname, i.e. if the TEMPLATE designate a logical pathname the translation to a physical pathname is performed before opening the stream. In order to create a unique file name, OPEN-TEMPORARY may loop internally up to MAX-TRIES times before giving up and signalling a CANNOT-CREATE-TEMPORARY-FILE condition.
  • Macro WITH-OUTPUT-TO-TEMPORARY-FILE ((stream &rest args) &body body)
    Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY with STREAM bound to the temporary file stream. Returns the pathname of the file that has been created. See OPEN-TEMPORARY for permitted options.
  • Macro WITH-OPEN-TEMPORARY-FILE ((stream &rest args &key keep &allow-other-keys) &body body)
    Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY with STREAM bound to the temporary file stream. Returns the values returned by BODY. By default, the file is deleted when BODY is exited. If a true value is passed in KEEP, the file is not deleted when the body is exited. See OPEN-TEMPORARY for more permitted options.