Я использую архиватор для создания архива, и в настоящее время я пытаюсь заменить свое решение сохранением .zip
на диске решением, которое будет добавлять файлы на лету и возвращать Archiver
в результате. Однако, похоже, что PassThrough
не запускает end
и finish
события, и это было, когда я использовал WriteStream
.
async generatePdfArchive(documents: PdfDocumentDto[]): Promise<archiver.Archiver> {
return new Promise(async (resolve, reject) => {
const output = new PassThrough();
const archive = archiver('zip', {
zlib: { level: 9 }
});
archive.pipe(output);
for (const document of documents) {
const pdf = await this.generatePdf(document);
archive.append(
pdf,
{ name: `${Date.now()}.pdf` }
);
}
archive.finalize();
output.end();
// Nothing was fired (except for the end event when I tried to read the output
output.on('finish', () => console.log('finished'));
output.on('close', () => console.log('close'));
output.on('end', () => console.log('end'));
archive.on('warning', () => console.log('archive warning'));
archive.on('error', () => console.log('archive error'));
});
}