Fix platform specific separators in recursive directory creation

This commit is contained in:
Shawn 2019-02-03 23:47:15 -06:00
parent c4dfba317e
commit 142684f134

View file

@ -8,12 +8,12 @@ const util = require('util');
const COMPRESSION_LEVEL = 5; const COMPRESSION_LEVEL = 5;
function mkdirSyncRecursive(dir) { function mkdirSyncRecursive(dir) {
let path = dir.replace(/\/$/, '').split('/'); let segments = dir.split(path.sep);
for (var i = 1; i <= path.length; i++) { for (let i = 1; i <= segments.length; i++) {
let segment = path.slice(0, i).join('/'); let segment = segments.slice(0, i).join('/');
if (segment.length > 0 && !fs.existsSync(segment)) { if (segment.length > 0 && !fs.existsSync(segment)) {
fs.mkdirSync(segment) fs.mkdirSync(segment);
} }
} }
} }
@ -206,6 +206,7 @@ async function unpackDirectory(directory, options = {}) {
try { try {
mkdirSyncRecursive(path.dirname(writePath)); mkdirSyncRecursive(path.dirname(writePath));
} catch (e) { } catch (e) {
console.log(e);
// Directory exists // Directory exists
} }
const fileWriteStream = fs.createWriteStream(writePath); const fileWriteStream = fs.createWriteStream(writePath);