MCPcopy Create free account
hub / github.com/vercel/vercel / createZip

Function createZip

packages/build-utils/src/lambda.ts:492–526  ·  view source on GitHub ↗
(files: Files)

Source from the content-addressed store, hash-verified

490}
491
492export async function createZip(files: Files): Promise<Buffer> {
493 const names = Object.keys(files).sort();
494
495 const symlinkTargets = new Map<string, string>();
496 for (const name of names) {
497 const file = files[name];
498 if (file.mode && isSymbolicLink(file.mode) && file.type === 'FileFsRef') {
499 const symlinkTarget = await readlink(file.fsPath);
500 symlinkTargets.set(name, symlinkTarget);
501 }
502 }
503
504 const zipFile = new ZipFile();
505 const zipBuffer = await new Promise<Buffer>((resolve, reject) => {
506 for (const name of names) {
507 const file = files[name];
508 const opts = { mode: file.mode, mtime };
509 const symlinkTarget = symlinkTargets.get(name);
510 if (typeof symlinkTarget === 'string') {
511 zipFile.addBuffer(Buffer.from(symlinkTarget, 'utf8'), name, opts);
512 } else if (file.mode && isDirectory(file.mode)) {
513 zipFile.addEmptyDirectory(name, opts);
514 } else {
515 const stream = file.toStream();
516 stream.on('error', reject);
517 zipFile.addReadStream(stream, name, opts);
518 }
519 }
520
521 zipFile.end();
522 streamToBuffer(zipFile.outputStream).then(resolve).catch(reject);
523 });
524
525 return zipBuffer;
526}
527
528export async function getLambdaOptionsFromFunction({
529 sourceFile,

Callers 2

createZipMethod · 0.85

Calls 8

isSymbolicLinkFunction · 0.90
isDirectoryFunction · 0.90
streamToBufferFunction · 0.85
sortMethod · 0.80
getMethod · 0.65
keysMethod · 0.45
setMethod · 0.45
toStreamMethod · 0.45

Tested by

no test coverage detected