add CCIO.File.with_temp for creating temporary files

This commit is contained in:
Simon Cruanes 2016-03-26 12:22:25 +01:00
parent 03350031a3
commit 13dad5b6ac
2 changed files with 14 additions and 0 deletions

View file

@ -329,4 +329,8 @@ module File = struct
| `File -> "file:" | `File -> "file:"
| `Dir -> "dir:" | `Dir -> "dir:"
) ^ f ) ^ 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 end

View file

@ -195,4 +195,14 @@ module File : sig
symlinks, etc.) *) symlinks, etc.) *)
val show_walk_item : walk_item -> string 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 end