From c214bb19d7d23fb17c5312124e3ba60fe7858d75 Mon Sep 17 00:00:00 2001 From: Jan Kryl Date: Wed, 16 Jul 2014 12:40:32 -0400 Subject: [PATCH] missing mkdirRecursive #89 --- lib/wrench.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/wrench.js b/lib/wrench.js index 01f5e95..4b087cf 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -484,6 +484,39 @@ var mkdirSyncRecursive = function(path, mode) { }; exports.mkdirSyncRecursive = mkdirSyncRecursive; +var mkdirRecursive = function(path, mode, clbk) { + var self = this; + path = _path.normalize(path) + + fs.mkdir(path, mode, function (err) { + if (!err) { + clbk(); + return; + } + if(err.code == "ENOENT") { + var slashIdx = path.lastIndexOf(_path.sep); + + if(slashIdx > 0) { + var parentPath = path.substring(0, slashIdx); + mkdirRecursive(parentPath, mode, function (err) { + if (err) { + clbk(err); + return; + } + mkdirRecursive(path, mode, clbk); + }); + return; + } + clbk(err); + } else if(err.code == "EEXIST") { + clbk(); + } else { + clbk(err); + } + }); +}; +exports.mkdirRecursive = mkdirRecursive; + exports.LineReader = function(filename, bufferSize) { this.bufferSize = bufferSize || 8192; this.buffer = "";