MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / buildZip

Function buildZip

apps/vis/server/test/lib/import-store.test.ts:13–25  ·  view source on GitHub ↗

Build an in-memory zip from a {path: contents} map (yazl refuses to emit * `..` entries, so traversal is tested via resolveSafeTarget directly).

(entries: Record<string, string>)

Source from the content-addressed store, hash-verified

11/** Build an in-memory zip from a {path: contents} map (yazl refuses to emit
12 * `..` entries, so traversal is tested via resolveSafeTarget directly). */
13function buildZip(entries: Record<string, string>): Promise<Buffer> {
14 return new Promise((resolve, reject) => {
15 const zip = new ZipFile();
16 for (const [name, data] of Object.entries(entries)) {
17 zip.addBuffer(Buffer.from(data, 'utf8'), name);
18 }
19 zip.end();
20 const chunks: Buffer[] = [];
21 (zip.outputStream as NodeJS.ReadableStream).on('data', (c: Buffer) => chunks.push(c));
22 (zip.outputStream as NodeJS.ReadableStream).on('end', () => { resolve(Buffer.concat(chunks)); });
23 (zip.outputStream as NodeJS.ReadableStream).on('error', reject);
24 });
25}
26
27const META_LINE = JSON.stringify({ type: 'metadata', protocol_version: '1.4', created_at: 1 });
28const WIRE = `${META_LINE}\n`;

Callers 1

Calls 4

onMethod · 0.65
resolveFunction · 0.50
endMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected