withTempDir<T> function
Creates a unique temporary directory, passes it to callback
and deletes it
and its contents after callback
finishes.
The callback
may return a Future, in which case the path isn't deleted
until that Future completes. Whether or not callback
returns a Future,
this creates and deletes the temporary directory synchronously; use
withTempDirAsync to delete it asynchronously instead.
If prefix
is passed, it's addded to the beginning of the temporary
directory's basename. If suffix
is passed, it's added to the end. If
parent
is passed, the temporary directory is created within that path;
otherwise, it's created within Directory.systemTemp.
Implementation
T withTempDir<T>(T callback(String dir),
{String? prefix, String? suffix, String? parent}) =>
withTempPath((path) {
Directory(path).createSync();
return callback(path);
}, prefix: prefix, suffix: suffix, parent: parent);