diff --git a/lib/fs.js b/lib/fs.js index 9a6eaa9b08..d5dc746e89 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1596,6 +1596,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) { @@ -1999,42 +2040,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); -};