From 142684f134b5101a2ae54d5bc7c5bdb3189b2ea2 Mon Sep 17 00:00:00 2001 From: Shawn Date: Sun, 3 Feb 2019 23:47:15 -0600 Subject: [PATCH] Fix platform specific separators in recursive directory creation --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a3d029d..037aed2 100644 --- a/index.js +++ b/index.js @@ -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);