Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5721674
fs: return Buffer from mkdtemp when prefix is a Buffer
hamidrezaghavami Jul 9, 2026
4b03819
test: restore missing mkdtemp async buffer tests
hamidrezaghavami Jul 11, 2026
5f6fca5
doc: update fs.mkdtemp() return types and history
hamidrezaghavami Jul 12, 2026
d7f0985
doc: physically wrap long lines in fs.md to fix markdown linter
hamidrezaghavami Jul 12, 2026
f7977f3
doc: fix markdown and yaml line lengths in fs.md
hamidrezaghavami Jul 12, 2026
34885d8
doc: update mkdtempSync and fsPromises.mkdtemp docs
hamidrezaghavami Jul 14, 2026
1a8da2a
doc: update disposable mkdtemp return types
hamidrezaghavami Jul 22, 2026
ca78ff4
doc: wrap lines in fs.md
hamidrezaghavami Jul 23, 2026
a271708
doc: add changes blocks to mkdtempDisposable functions
hamidrezaghavami Jul 23, 2026
728fb8d
doc: update encoding default for mkdtemp
hamidrezaghavami Sep 4, 2026
f4664f1
doc: update missing encoding default for fsPromises.mkdtemp
hamidrezaghavami Sep 4, 2026
11d4f55
doc: add changes YAML entries for mkdtemp encoding default
hamidrezaghavami Sep 4, 2026
0b55cab
Update test/parallel/test-fs-mkdtemp-buffer.js
hamidrezaghavami Sep 4, 2026
c11bd20
doc: fix YAML changes indentation for mkdtemp encoding default
hamidrezaghavami Sep 4, 2026
cccc0fa
doc: simplify version entry format for mkdtemp
hamidrezaghavami Sep 4, 2026
9d77adc
Update doc/api/fs.md
hamidrezaghavami Sep 4, 2026
fe50452
ci: re-run workflows
hamidrezaghavami Sep 5, 2026
b2b1410
doc: use REPLACEME for remaining mkdtemp versions
hamidrezaghavami Sep 5, 2026
c866ac7
doc: add missing YAML
hamidrezaghavami Sep 5, 2026
6bd088c
Update doc/api/fs.md
hamidrezaghavami Sep 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,9 @@ makeDirectory().catch(console.error);
<!-- YAML
added: v10.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/64397
description: The `encoding` option now defaults to `'buffer'` if `prefix` is a `Buffer`.
- version:
- v20.6.0
- v18.19.0
Expand All @@ -1651,7 +1654,7 @@ changes:

* `prefix` {string|Buffer|URL}
* `options` {string|Object}
* `encoding` {string} **Default:** `'utf8'`
* `encoding` {string} **Default:** `'utf8'` (or `'buffer'` if `prefix` is a `Buffer`)
Comment thread
aduh95 marked this conversation as resolved.
* Returns: {Promise} Fulfills with the created directory path.
If `encoding` is `'buffer'`, then the resulting directory
path is returned as a {Buffer}. Otherwise, the path is returned as a
Expand Down Expand Up @@ -1688,11 +1691,15 @@ characters directly to the `prefix` string. For instance, given a directory

<!-- YAML
added: v24.4.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/64397
description: The `encoding` option now defaults to `'buffer'` if `prefix` is a `Buffer`.
-->

* `prefix` {string|Buffer|URL}
* `options` {string|Object}
* `encoding` {string} **Default:** `'utf8'`
* `encoding` {string} **Default:** `'utf8'` (or `'buffer'` if `prefix` is a `Buffer`)
Comment thread
hamidrezaghavami marked this conversation as resolved.
* Returns: {Promise} Fulfills with a Promise for an async-disposable Object:
* `path` {string|Buffer} The path of the created directory.
* `remove` {AsyncFunction} A function which removes the created directory.
Expand Down Expand Up @@ -3978,6 +3985,9 @@ See the POSIX mkdir(2) documentation for more details.
<!-- YAML
added: v5.10.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/64397
description: The `encoding` option now defaults to `'buffer'` if `prefix` is a `Buffer`.
- version:
- v20.6.0
- v18.19.0
Expand Down Expand Up @@ -4008,7 +4018,7 @@ changes:

* `prefix` {string|Buffer|URL}
* `options` {string|Object}
* `encoding` {string} **Default:** `'utf8'`
* `encoding` {string} **Default:** `'utf8'` (or `'buffer'` if `prefix` is a `Buffer`)
* `callback` {Function}
* `err` {Error}
* `directory` {string|Buffer}
Expand Down Expand Up @@ -6490,6 +6500,9 @@ See the POSIX mkdir(2) documentation for more details.
<!-- YAML
added: v5.10.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/64397
description: The `encoding` option now defaults to `'buffer'` if `prefix` is a `Buffer`.
- version:
- v20.6.0
- v18.19.0
Expand All @@ -6504,7 +6517,7 @@ changes:

* `prefix` {string|Buffer|URL}
* `options` {string|Object}
* `encoding` {string} **Default:** `'utf8'`
* `encoding` {string} **Default:** `'utf8'` (or `'buffer'` if `prefix` is a `Buffer`)
* Returns: {string|Buffer}

Returns the created directory path. If `encoding` is `'buffer'`, then the
Expand All @@ -6521,11 +6534,15 @@ object with an `encoding` property specifying the character encoding to use.

<!-- YAML
added: v24.4.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/64397
description: The `encoding` option now defaults to `'buffer'` if `prefix` is a `Buffer`.
-->

* `prefix` {string|Buffer|URL}
* `options` {string|Object}
* `encoding` {string} **Default:** `'utf8'`
* `encoding` {string} **Default:** `'utf8'` (or `'buffer'` if `prefix` is a `Buffer`)
* Returns: {Object} A disposable object:
* `path` {string|Buffer} The path of the created directory.
* `remove` {Function} A function which removes the created directory.
Expand Down
12 changes: 9 additions & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3679,7 +3679,9 @@ function mkdtemp(prefix, options, callback) {
if (h !== null && vfsResult(h.mkdtemp(prefix, typeof options === 'function' ? undefined : options), callback)) return;

options = getOptions(options);

if (BufferIsBuffer(prefix)) {
options = { ...options, encoding: 'buffer' };
}
prefix = getValidatedPath(prefix, 'prefix');
warnOnNonPortableTemplate(prefix);

Expand All @@ -3702,7 +3704,9 @@ function mkdtempSync(prefix, options) {
}

options = getOptions(options);

if (BufferIsBuffer(prefix)) {
options = { ...options, encoding: 'buffer' };
}
prefix = getValidatedPath(prefix, 'prefix');
warnOnNonPortableTemplate(prefix);
return binding.mkdtemp(prefix, options.encoding);
Expand All @@ -3718,7 +3722,9 @@ function mkdtempSync(prefix, options) {
*/
function mkdtempDisposableSync(prefix, options) {
options = getOptions(options);

if (BufferIsBuffer(prefix)) {
options = { ...options, encoding: 'buffer' };
}
prefix = getValidatedPath(prefix, 'prefix');
warnOnNonPortableTemplate(prefix);

Expand Down
9 changes: 6 additions & 3 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -2039,9 +2039,10 @@ async function mkdtemp(prefix, options) {
const promise = h.mkdtemp(prefix, options);
if (promise !== undefined) return await promise;
}

options = getOptions(options);

if (BufferIsBuffer(prefix)) {
options = { ...options, encoding: 'buffer' };
}
prefix = getValidatedPath(prefix, 'prefix');
warnOnNonPortableTemplate(prefix);

Expand All @@ -2054,7 +2055,9 @@ async function mkdtemp(prefix, options) {

async function mkdtempDisposable(prefix, options) {
options = getOptions(options);

if (BufferIsBuffer(prefix)) {
options = { ...options, encoding: 'buffer' };
}
prefix = getValidatedPath(prefix, 'prefix');
warnOnNonPortableTemplate(prefix);

Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-fs-mkdtemp-buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const prefixString = path.join(tmpdir.path, 'buffer-');
const prefixBuffer = Buffer.from(prefixString);

// 1. Test Sync API
const resultSync = fs.mkdtempSync(prefixBuffer);
assert.strictEqual(Buffer.isBuffer(resultSync), true);

// 2. Test Callback API
fs.mkdtemp(prefixBuffer, common.mustSucceed((result) => {
assert.strictEqual(Buffer.isBuffer(result), true);
}));

// 3. Test Promises API
fs.promises.mkdtemp(prefixBuffer)
.then(common.mustCall((resultPromise) => {
assert.strictEqual(Buffer.isBuffer(resultPromise), true);
}));
5 changes: 2 additions & 3 deletions test/parallel/test-fs-mkdtemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ function handler(err, folder) {
{
const tmpFolder = fs.mkdtempSync(Buffer.from(tmpdir.resolve('foo.')));

assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
assert.strictEqual(path.basename(tmpFolder.toString()).length, 'foo.XXXXXX'.length);
assert(fs.existsSync(tmpFolder));

const utf8 = fs.mkdtempSync(Buffer.from(tmpdir.resolve('\u0222abc.')));
assert.strictEqual(Buffer.byteLength(path.basename(utf8)),
assert.strictEqual(Buffer.byteLength(path.basename(utf8.toString())),
Buffer.byteLength('\u0222abc.XXXXXX'));
assert(fs.existsSync(utf8));

fs.mkdtemp(Buffer.from(tmpdir.resolve('bar.')), common.mustCall(handler));

// Same test as above, but making sure that passing an options object doesn't
Expand Down
Loading