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>)
| 11 | /** Build an in-memory zip from a {path: contents} map (yazl refuses to emit |
| 12 | * `..` entries, so traversal is tested via resolveSafeTarget directly). */ |
| 13 | function 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 | |
| 27 | const META_LINE = JSON.stringify({ type: 'metadata', protocol_version: '1.4', created_at: 1 }); |
| 28 | const WIRE = `${META_LINE}\n`; |
no test coverage detected