(entries: Array<{ name: string; data: string | Buffer }>)
| 1022 | } |
| 1023 | |
| 1024 | async function createZipBuffer(entries: Array<{ name: string; data: string | Buffer }>): Promise<Buffer> { |
| 1025 | return new Promise((resolve, reject) => { |
| 1026 | const zipfile = new yazl.ZipFile(); |
| 1027 | const chunks: Buffer[] = []; |
| 1028 | zipfile.outputStream.on('data', (chunk) => chunks.push(chunk)); |
| 1029 | zipfile.outputStream.on('end', () => { |
| 1030 | resolve(Buffer.concat(chunks)); |
| 1031 | }); |
| 1032 | zipfile.outputStream.on('error', reject); |
| 1033 | for (const entry of entries) { |
| 1034 | zipfile.addBuffer(Buffer.isBuffer(entry.data) ? entry.data : Buffer.from(entry.data), entry.name); |
| 1035 | } |
| 1036 | zipfile.end(); |
| 1037 | }); |
| 1038 | } |
| 1039 | |
| 1040 | async function serveOnce(buffer: Buffer): Promise<string> { |
| 1041 | const { createServer } = await import('node:http'); |
no test coverage detected