| 62 | } |
| 63 | |
| 64 | export async function compressFolder(items: ScanItem[]): Promise<Uint8Array> { |
| 65 | const zipData: AsyncZippable = {}; |
| 66 | |
| 67 | for (const item of items) { |
| 68 | if (item.isDir) { |
| 69 | zipData[item.path] = [new Uint8Array(0), { level: 0 }]; |
| 70 | } else if (item.file) { |
| 71 | const buffer = await item.file.arrayBuffer(); |
| 72 | zipData[item.path] = [new Uint8Array(buffer), { level: 4 }]; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return new Promise((resolve, reject) => { |
| 77 | zip(zipData, (err, data) => { |
| 78 | if (err) { |
| 79 | reject(err); |
| 80 | } else { |
| 81 | resolve(data); |
| 82 | } |
| 83 | }); |
| 84 | }); |
| 85 | } |