Skip to content

Commit 646fb6e

Browse files
fs: return Buffer from mkdtemp when prefix is a Buffer
1 parent 8fec65d commit 646fb6e

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

lib/fs.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,9 @@ function mkdtemp(prefix, options, callback) {
35713571
if (h !== null && vfsResult(h.mkdtemp(prefix, typeof options === 'function' ? undefined : options), callback)) return;
35723572

35733573
options = getOptions(options);
3574-
3574+
if (Buffer.isBuffer(prefix)) {
3575+
options.encoding = 'buffer';
3576+
}
35753577
prefix = getValidatedPath(prefix, 'prefix');
35763578
warnOnNonPortableTemplate(prefix);
35773579

@@ -3594,7 +3596,9 @@ function mkdtempSync(prefix, options) {
35943596
}
35953597

35963598
options = getOptions(options);
3597-
3599+
if (Buffer.isBuffer(prefix)) {
3600+
options.encoding = 'buffer';
3601+
}
35983602
prefix = getValidatedPath(prefix, 'prefix');
35993603
warnOnNonPortableTemplate(prefix);
36003604
return binding.mkdtemp(prefix, options.encoding);
@@ -3610,7 +3614,9 @@ function mkdtempSync(prefix, options) {
36103614
*/
36113615
function mkdtempDisposableSync(prefix, options) {
36123616
options = getOptions(options);
3613-
3617+
if (Buffer.isBuffer(prefix)) {
3618+
options.encoding = 'buffer';
3619+
}
36143620
prefix = getValidatedPath(prefix, 'prefix');
36153621
warnOnNonPortableTemplate(prefix);
36163622

lib/internal/fs/promises.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,9 +2024,10 @@ async function mkdtemp(prefix, options) {
20242024
const promise = h.mkdtemp(prefix, options);
20252025
if (promise !== undefined) return await promise;
20262026
}
2027-
20282027
options = getOptions(options);
2029-
2028+
if (Buffer.isBuffer(prefix)) {
2029+
options.encoding = 'buffer';
2030+
}
20302031
prefix = getValidatedPath(prefix, 'prefix');
20312032
warnOnNonPortableTemplate(prefix);
20322033

@@ -2039,7 +2040,9 @@ async function mkdtemp(prefix, options) {
20392040

20402041
async function mkdtempDisposable(prefix, options) {
20412042
options = getOptions(options);
2042-
2043+
if (Buffer.isBuffer(prefix)) {
2044+
options.encoding = 'buffer';
2045+
}
20432046
prefix = getValidatedPath(prefix, 'prefix');
20442047
warnOnNonPortableTemplate(prefix);
20452048

0 commit comments

Comments
 (0)