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

Function createZipBuffer

packages/agent-core/test/plugin/archive.test.ts:10–30  ·  view source on GitHub ↗
(
  entries: Array<{ name: string; data: string | Buffer; mode?: number }>,
)

Source from the content-addressed store, hash-verified

8import { downloadZip, extractZip } from '../../src/plugin/archive';
9
10async function createZipBuffer(
11 entries: Array<{ name: string; data: string | Buffer; mode?: number }>,
12): Promise<Buffer> {
13 return new Promise((resolve, reject) => {
14 const zipfile = new yazl.ZipFile();
15 const chunks: Buffer[] = [];
16 zipfile.outputStream.on('data', (chunk) => chunks.push(chunk));
17 zipfile.outputStream.on('end', () => {
18 resolve(Buffer.concat(chunks));
19 });
20 zipfile.outputStream.on('error', reject);
21 for (const entry of entries) {
22 zipfile.addBuffer(
23 Buffer.isBuffer(entry.data) ? entry.data : Buffer.from(entry.data),
24 entry.name,
25 entry.mode === undefined ? undefined : { mode: entry.mode },
26 );
27 }
28 zipfile.end();
29 });
30}
31
32function createMinimalZip(entryName: string, content: string): Buffer {
33 const nameBuf = Buffer.from(entryName, 'utf8');

Callers 1

archive.test.tsFile · 0.70

Calls 4

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

Tested by

no test coverage detected