View Source z_tempfile (zotonic_stdlib v1.23.1)
Simple temporary file handling, deletes the file when the calling process stops or crashes.
Summary
Functions
Delete all tempfiles not modified in the last day.
Check if the file is a temporary filename.
Add a process to the tempfile monitor. The tempfile is deleted after all attached processes stopped or are detached.
Remove a process from the tempfile monitor. The tempfile is deleted after all attached processes stopped or are detached.
Like new/0 but also return the Pid of the monitoring process.
Like new/1 but also return the Pid of the monitoring process.
Return a new unique filename, start a monitoring process to clean it up after use. The file must be created and written within 10 seconds, or it will be deleted.
Return a new unique filename, start a monitoring process to clean it up after use. The file must be created and written within 10 seconds, or it will be deleted.
return a unique temporary filename located in the TMP directory.
return a unique temporary filename with the given extension.
Returns the path where to store temporary files.
Functions
-spec cleanup() -> ok.
Delete all tempfiles not modified in the last day.
-spec is_tempfile(file:filename_all()) -> boolean().
Check if the file is a temporary filename.
-spec monitored_attach(pid()) -> ok.
Add a process to the tempfile monitor. The tempfile is deleted after all attached processes stopped or are detached.
-spec monitored_detach(pid()) -> ok.
Remove a process from the tempfile monitor. The tempfile is deleted after all attached processes stopped or are detached.
-spec monitored_new() -> {ok, {pid(), file:filename_all()}}.
Like new/0 but also return the Pid of the monitoring process.
-spec monitored_new(string() | binary()) -> {ok, {pid(), file:filename_all()}}.
Like new/1 but also return the Pid of the monitoring process.
-spec new() -> file:filename_all().
Return a new unique filename, start a monitoring process to clean it up after use. The file must be created and written within 10 seconds, or it will be deleted.
-spec new(string() | binary()) -> file:filename_all().
Return a new unique filename, start a monitoring process to clean it up after use. The file must be created and written within 10 seconds, or it will be deleted.
-spec tempfile() -> file:filename_all().
return a unique temporary filename located in the TMP directory.
-spec tempfile(string() | binary()) -> file:filename_all().
return a unique temporary filename with the given extension.
-spec temppath() -> file:filename_all().
Returns the path where to store temporary files.