diff --git a/src/core/CCIO.ml b/src/core/CCIO.ml index b3c1231a..b8c12cca 100644 --- a/src/core/CCIO.ml +++ b/src/core/CCIO.ml @@ -329,4 +329,8 @@ module File = struct | `File -> "file:" | `Dir -> "dir:" ) ^ f + + let with_temp ?temp_dir ~prefix ~suffix f = + let name = Filename.temp_file ?temp_dir prefix suffix in + finally_ f name ~h:remove_noerr end diff --git a/src/core/CCIO.mli b/src/core/CCIO.mli index 92e6a119..98134e4d 100644 --- a/src/core/CCIO.mli +++ b/src/core/CCIO.mli @@ -195,4 +195,14 @@ module File : sig symlinks, etc.) *) val show_walk_item : walk_item -> string + + val with_temp : + ?temp_dir:string -> prefix:string -> suffix:string -> + (string -> 'a) -> 'a + (** [with_temp ~prefix ~suffix f] will call [f] with the name of a new + temporary file (located in [temp_dir]). + After [f] returns, the file is deleted. Best to be used in + combination with {!with_out}. + See {!Filename.temp_file} + @since NEXT_RELEASE *) end