Skip to content

Commit 791e2d2

Browse files
doc: clarify return type of fs.mkdtemp*
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> Co-authored-by: Hamid Reza Ghavami <hamidr.ghavami@gmail.com> PR-URL: #65743 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 1e9fd95 commit 791e2d2

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

doc/api/fs.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,10 @@ changes:
16521652
* `prefix` {string|Buffer|URL}
16531653
* `options` {string|Object}
16541654
* `encoding` {string} **Default:** `'utf8'`
1655-
* Returns: {Promise} Fulfills with a string containing the file system path
1656-
of the newly created temporary directory.
1655+
* Returns: {Promise} Fulfills with the created directory path.
1656+
If `encoding` is `'buffer'`, then the resulting directory
1657+
path is returned as a {Buffer}. Otherwise, the path is returned as a
1658+
{string} using the specified encoding.
16571659
16581660
Creates a unique temporary directory. A unique directory name is generated by
16591661
appending six random characters to the end of the provided `prefix`. Due to
@@ -1692,14 +1694,15 @@ added: v24.4.0
16921694
* `options` {string|Object}
16931695
* `encoding` {string} **Default:** `'utf8'`
16941696
* Returns: {Promise} Fulfills with a Promise for an async-disposable Object:
1695-
* `path` {string} The path of the created directory.
1697+
* `path` {string|Buffer} The path of the created directory.
16961698
* `remove` {AsyncFunction} A function which removes the created directory.
16971699
* `[Symbol.asyncDispose]` {AsyncFunction} The same as `remove`.
16981700
16991701
The resulting Promise holds an async-disposable object whose `path` property
1700-
holds the created directory path. When the object is disposed, the directory
1701-
and its contents will be removed asynchronously if it still exists. If the
1702-
directory cannot be deleted, disposal will throw an error. The object has an
1702+
holds the created directory path. If `encoding` is `'buffer'`, the `path` will
1703+
also be a {Buffer}, otherwise a {string}. When the object is disposed, the
1704+
directory and its contents will be removed asynchronously if it still exists. If
1705+
the directory cannot be deleted, disposal will throw an error. The object has an
17031706
async `remove()` method which will perform the same task.
17041707
17051708
Both this function and the disposal function on the resulting object are
@@ -4008,7 +4011,7 @@ changes:
40084011
* `encoding` {string} **Default:** `'utf8'`
40094012
* `callback` {Function}
40104013
* `err` {Error}
4011-
* `directory` {string}
4014+
* `directory` {string|Buffer}
40124015
40134016
Creates a unique temporary directory.
40144017
@@ -4018,12 +4021,14 @@ inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
40184021
notably the BSDs, can return more than six random characters, and replace
40194022
trailing `X` characters in `prefix` with random characters.
40204023
4021-
The created directory path is passed as a string to the callback's second
4022-
parameter.
4023-
40244024
The optional `options` argument can be a string specifying an encoding, or an
40254025
object with an `encoding` property specifying the character encoding to use.
40264026
4027+
The created directory path is passed to the callback's second parameter. If
4028+
`encoding` is `'buffer'`, then the resulting directory path is passed as a
4029+
{Buffer}. Otherwise, the path is passed as a {string} using the specified
4030+
encoding.
4031+
40274032
```mjs
40284033
import { mkdtemp } from 'node:fs';
40294034
import { join } from 'node:path';
@@ -6500,9 +6505,11 @@ changes:
65006505
* `prefix` {string|Buffer|URL}
65016506
* `options` {string|Object}
65026507
* `encoding` {string} **Default:** `'utf8'`
6503-
* Returns: {string}
6508+
* Returns: {string|Buffer}
65046509
6505-
Returns the created directory path.
6510+
Returns the created directory path. If `encoding` is `'buffer'`, then the
6511+
resulting directory path is returned as a {Buffer}. Otherwise, the path
6512+
is returned as a {string} using the specified encoding.
65066513
65076514
For detailed information, see the documentation of the asynchronous version of
65086515
this API: [`fs.mkdtemp()`][].
@@ -6520,15 +6527,15 @@ added: v24.4.0
65206527
* `options` {string|Object}
65216528
* `encoding` {string} **Default:** `'utf8'`
65226529
* Returns: {Object} A disposable object:
6523-
* `path` {string} The path of the created directory.
6530+
* `path` {string|Buffer} The path of the created directory.
65246531
* `remove` {Function} A function which removes the created directory.
65256532
* `[Symbol.dispose]` {Function} The same as `remove`.
65266533
65276534
Returns a disposable object whose `path` property holds the created directory
6528-
path. When the object is disposed, the directory and its contents will be
6529-
removed if it still exists. If the directory cannot be deleted, disposal will
6530-
throw an error. The object has a `remove()` method which will perform the same
6531-
task.
6535+
path. If `encoding` is `'buffer'`, the `path` will be a {Buffer}. When the
6536+
object is disposed, the directory and its contents will be removed if it still
6537+
exists. If the directory cannot be deleted, disposal will throw an error. The
6538+
object has a `remove()` method which will perform the same task.
65326539
65336540
See the [MDN documentation on `using` statements][`using`] for more information about
65346541
explicit resource management.

0 commit comments

Comments
 (0)