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