diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-26 23:21:49 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-26 23:21:49 +0000 |
| commit | 9196e8bc6f2ff2c59a9b4fde4813e7bc26b8c23d (patch) | |
| tree | c42bfa3fb88f2348018c63f7dc1a64299a666355 /lib/zipfile.js | |
| parent | f5fbc6e4aface5c6c9537b38d1650b0d37e3cbc1 (diff) | |
Extract joinPath and splitPath for zip files
Diffstat (limited to 'lib/zipfile.js')
| -rw-r--r-- | lib/zipfile.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/zipfile.js b/lib/zipfile.js index 7c534c7..ae51310 100644 --- a/lib/zipfile.js +++ b/lib/zipfile.js @@ -3,6 +3,8 @@ var JSZip = require("jszip"); var promises = require("./promises"); exports.openArrayBuffer = openArrayBuffer; +exports.splitPath = splitPath; +exports.joinPath = joinPath; function openArrayBuffer(arrayBuffer) { var zipFile = new JSZip(arrayBuffer); @@ -35,3 +37,21 @@ function openArrayBuffer(arrayBuffer) { toBuffer: toBuffer }; } + +function splitPath(path) { + var lastIndex = path.lastIndexOf("/"); + if (lastIndex === -1) { + return {dirname: "", basename: path}; + } else { + return { + dirname: path.substring(0, lastIndex), + basename: path.substring(lastIndex + 1) + }; + } +} + +function joinPath() { + return Array.prototype.filter.call(arguments, function(path) { + return path; + }).join("/"); +} |
