fsPromises.mkdtempDisposable(prefix[, options])


生成的 Promise 包含一个异步可释放对象,其 path 属性保存了已创建的目录路径。当对象被释放时,如果目录及其内容仍然存在,则它们将被异步删除。如果无法删除目录,则处置将引发错误。该对象具有一个异步 remove() 方法,该方法将执行相同的任务。

¥The resulting Promise holds an async-disposable object whose path property holds the created directory path. When the object is disposed, the directory and its contents will be removed asynchronously if it still exists. If the directory cannot be deleted, disposal will throw an error. The object has an async remove() method which will perform the same task.

此函数和结果对象上的处置函数都是异步的,因此应与 await using dir = await fsPromises.mkdtempDisposable('prefix') 中的 await + await using 一起使用。

¥Both this function and the disposal function on the resulting object are async, so it should be used with await + await using as in await using dir = await fsPromises.mkdtempDisposable('prefix').

有关详细信息,请参阅 fsPromises.mkdtemp() 的文档。

¥For detailed information, see the documentation of fsPromises.mkdtemp().

可选的 options 参数可以是指定编码的字符串,也可以是具有 encoding 属性(指定要使用的字符编码)的对象。

¥The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use.