Fix platform specific separators in recursive directory creation
This commit is contained in:
parent
c4dfba317e
commit
142684f134
1 changed files with 5 additions and 4 deletions
9
index.js
9
index.js
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue