Skip to content

Commit

Permalink
fs: move mkdtemp* functions near static functions
Browse files Browse the repository at this point in the history
PR-URL: #6828
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
thefourtheye authored and rvagg committed Jun 2, 2016
1 parent c068880 commit c4329aa
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
};

0 comments on commit c4329aa

Please sign in to comment.