MCPcopy
hub / github.com/serverless/serverless / addTree

Function addTree

packages/serverless/lib/plugins/python/lib/zipTree.js:10–25  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

8 * @return {Promise} a promise offering the original JSZip object.
9 */
10async 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.

Callers 2

packRequirementsFunction · 0.90
zipRequirementsFunction · 0.90

Calls 1

readFileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…