diff --git a/lib/fs.js b/lib/fs.js index 31916e5b62c793..7642b5cb74616f 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1590,6 +1590,47 @@ fs.realpath = function realpath(path, options, callback) { }; +fs.mkdtemp = function(prefix, options, callback_) { + var callback = maybeCallback(callback_); + if (!prefix || typeof prefix !== 'string') + throw new TypeError('filename prefix is required'); + + options = options || {}; + if (typeof options === 'function') { + callback = options; + options = {}; + } else if (typeof options === 'string') { + options = {encoding: options}; + } + if (typeof options !== 'object') + throw new TypeError('"options" must be a string or an object'); + + if (!nullCheck(prefix, callback)) { + return; + } + + var req = new FSReqWrap(); + req.oncomplete = callback; + + binding.mkdtemp(prefix + 'XXXXXX', options.encoding, req); +}; + + +fs.mkdtempSync = function(prefix, options) { + if (!prefix || typeof prefix !== 'string') + throw new TypeError('filename prefix is required'); + + options = options || {}; + if (typeof options === 'string') + options = {encoding: options}; + if (typeof options !== 'object') + throw new TypeError('"options" must be a string or an object'); + nullCheck(prefix); + + return binding.mkdtemp(prefix + 'XXXXXX', options.encoding); +}; + + var pool; function allocNewPool(poolSize) { @@ -1993,42 +2034,3 @@ SyncWriteStream.prototype.destroy = function() { }; SyncWriteStream.prototype.destroySoon = SyncWriteStream.prototype.destroy; - -fs.mkdtemp = function(prefix, options, callback_) { - var callback = maybeCallback(callback_); - if (!prefix || typeof prefix !== 'string') - throw new TypeError('filename prefix is required'); - - options = options || {}; - if (typeof options === 'function') { - callback = options; - options = {}; - } else if (typeof options === 'string') { - options = {encoding: options}; - } - if (typeof options !== 'object') - throw new TypeError('"options" must be a string or an object'); - - if (!nullCheck(prefix, callback)) { - return; - } - - var req = new FSReqWrap(); - req.oncomplete = callback; - - binding.mkdtemp(prefix + 'XXXXXX', options.encoding, req); -}; - -fs.mkdtempSync = function(prefix, options) { - if (!prefix || typeof prefix !== 'string') - throw new TypeError('filename prefix is required'); - - options = options || {}; - if (typeof options === 'string') - options = {encoding: options}; - if (typeof options !== 'object') - throw new TypeError('"options" must be a string or an object'); - nullCheck(prefix); - - return binding.mkdtemp(prefix + 'XXXXXX', options.encoding); -};