* Add a directory recursively to a zip file. Files in src will be added to the top folder of zip. * @param {JSZip} zip a zip object in the folder you want to add files to. * @param {string} src the source folder. * @return {Promise} a promise offering the original JSZip object.
(zip, src)
| 8 | * @return {Promise} a promise offering the original JSZip object. |
| 9 | */ |
| 10 | async function addTree(zip, src) { |
| 11 | const srcN = path.normalize(src) |
| 12 | const names = await fse.readdir(srcN) |
| 13 | for (const name of names) { |
| 14 | const srcPath = path.join(srcN, name) |
| 15 | const stat = await fse.stat(srcPath) |
| 16 | if (stat.isDirectory()) { |
| 17 | await addTree(zip.folder(name), srcPath) |
| 18 | } else { |
| 19 | const opts = { date: stat.mtime, unixPermissions: stat.mode } |
| 20 | const data = await fse.readFile(srcPath) |
| 21 | zip.file(name, data, opts) |
| 22 | } |
| 23 | } |
| 24 | return zip |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Write zip contents to a file. |
no test coverage detected
searching dependent graphs…