-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This uses libuv's mkdtemp function to provide a way to create a temporary folder, using a prefix as the path. The prefix is appended six random characters. The callback function will receive the name of the folder that was created. Usage example: fs.mkdtemp('/tmp/foo-', function(err, folder) { console.log(folder); // Prints: /tmp/foo-Tedi42 }); The fs.mkdtempSync version is also provided. Usage example: console.log(fs.mkdtemp('/tmp/foo-')); // Prints: tmp/foo-Tedi42 This pull request also includes the relevant documentation changes and tests. PR-URL: #5333 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
- Loading branch information
1 parent
5824522
commit 2269d7d
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Buffer = require('buffer').Buffer; | ||
|
||
common.refreshTmpDir(); | ||
|
||
const tmpFolder = fs.mkdtempSync(path.join(common.tmpDir, 'foo.')); | ||
|
||
assert(path.basename(tmpFolder).length === 'foo.XXXXXX'.length); | ||
assert(common.fileExists(tmpFolder)); | ||
|
||
const utf8 = fs.mkdtempSync(path.join(common.tmpDir, '\u0222abc.')); | ||
assert.equal(Buffer.byteLength(path.basename(utf8)), | ||
Buffer.byteLength('\u0222abc.XXXXXX')); | ||
assert(common.fileExists(utf8)); | ||
|
||
fs.mkdtemp( | ||
path.join(common.tmpDir, 'bar.'), | ||
common.mustCall(function(err, folder) { | ||
assert.ifError(err); | ||
assert(common.fileExists(folder)); | ||
}) | ||
); |