Skip to content

Commit 131f1db

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 8a9f89b commit 131f1db

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
@@ -1625,8 +1625,10 @@ changes:
16251625
* `prefix` {string|Buffer|URL}
16261626
* `options` {string|Object}
16271627
* `encoding` {string} **Default:** `'utf8'`
1628-
* Returns: {Promise} Fulfills with a string containing the file system path
1629-
of the newly created temporary directory.
1628+
* Returns: {Promise} Fulfills with the created directory path.
1629+
If `encoding` is `'buffer'`, then the resulting directory
1630+
path is returned as a {Buffer}. Otherwise, the path is returned as a
1631+
{string} using the specified encoding.
16301632
16311633
Creates a unique temporary directory. A unique directory name is generated by
16321634
appending six random characters to the end of the provided `prefix`. Due to
@@ -1665,14 +1667,15 @@ added: v24.4.0
16651667
* `options` {string|Object}
16661668
* `encoding` {string} **Default:** `'utf8'`
16671669
* Returns: {Promise} Fulfills with a Promise for an async-disposable Object:
1668-
* `path` {string} The path of the created directory.
1670+
* `path` {string|Buffer} The path of the created directory.
16691671
* `remove` {AsyncFunction} A function which removes the created directory.
16701672
* `[Symbol.asyncDispose]` {AsyncFunction} The same as `remove`.
16711673
16721674
The resulting Promise holds an async-disposable object whose `path` property
1673-
holds the created directory path. When the object is disposed, the directory
1674-
and its contents will be removed asynchronously if it still exists. If the
1675-
directory cannot be deleted, disposal will throw an error. The object has an
1675+
holds the created directory path. If `encoding` is `'buffer'`, the `path` will
1676+
also be a {Buffer}, otherwise a {string}. When the object is disposed, the
1677+
directory and its contents will be removed asynchronously if it still exists. If
1678+
the directory cannot be deleted, disposal will throw an error. The object has an
16761679
async `remove()` method which will perform the same task.
16771680
16781681
Both this function and the disposal function on the resulting object are
@@ -3951,7 +3954,7 @@ changes:
39513954
* `encoding` {string} **Default:** `'utf8'`
39523955
* `callback` {Function}
39533956
* `err` {Error}
3954-
* `directory` {string}
3957+
* `directory` {string|Buffer}
39553958
39563959
Creates a unique temporary directory.
39573960
@@ -3961,12 +3964,14 @@ inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
39613964
notably the BSDs, can return more than six random characters, and replace
39623965
trailing `X` characters in `prefix` with random characters.
39633966
3964-
The created directory path is passed as a string to the callback's second
3965-
parameter.
3966-
39673967
The optional `options` argument can be a string specifying an encoding, or an
39683968
object with an `encoding` property specifying the character encoding to use.
39693969
3970+
The created directory path is passed to the callback's second parameter. If
3971+
`encoding` is `'buffer'`, then the resulting directory path is passed as a
3972+
{Buffer}. Otherwise, the path is passed as a {string} using the specified
3973+
encoding.
3974+
39703975
```mjs
39713976
import { mkdtemp } from 'node:fs';
39723977
import { join } from 'node:path';
@@ -6423,9 +6428,11 @@ changes:
64236428
* `prefix` {string|Buffer|URL}
64246429
* `options` {string|Object}
64256430
* `encoding` {string} **Default:** `'utf8'`
6426-
* Returns: {string}
6431+
* Returns: {string|Buffer}
64276432
6428-
Returns the created directory path.
6433+
Returns the created directory path. If `encoding` is `'buffer'`, then the
6434+
resulting directory path is returned as a {Buffer}. Otherwise, the path
6435+
is returned as a {string} using the specified encoding.
64296436
64306437
For detailed information, see the documentation of the asynchronous version of
64316438
this API: [`fs.mkdtemp()`][].
@@ -6443,15 +6450,15 @@ added: v24.4.0
64436450
* `options` {string|Object}
64446451
* `encoding` {string} **Default:** `'utf8'`
64456452
* Returns: {Object} A disposable object:
6446-
* `path` {string} The path of the created directory.
6453+
* `path` {string|Buffer} The path of the created directory.
64476454
* `remove` {Function} A function which removes the created directory.
64486455
* `[Symbol.dispose]` {Function} The same as `remove`.
64496456
64506457
Returns a disposable object whose `path` property holds the created directory
6451-
path. When the object is disposed, the directory and its contents will be
6452-
removed if it still exists. If the directory cannot be deleted, disposal will
6453-
throw an error. The object has a `remove()` method which will perform the same
6454-
task.
6458+
path. If `encoding` is `'buffer'`, the `path` will be a {Buffer}. When the
6459+
object is disposed, the directory and its contents will be removed if it still
6460+
exists. If the directory cannot be deleted, disposal will throw an error. The
6461+
object has a `remove()` method which will perform the same task.
64556462
64566463
See the [MDN documentation on `using` statements][`using`] for more information about
64576464
explicit resource management.

0 commit comments

Comments
 (0)