Я использую архив nodejs для создания моего zip-файла. Мне нужно скачать этот zip-файл через ax ios.
, это мой код node js.
let zipFile = fs.createWriteStream(zipFilePath);
var archive = ar('zip');
zipFile.on('close', () => {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
});
zipFile.on('end', () => {
console.log('Data has been drained');
});
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
console.log('worning');
} else {
throw err;
}
});
archive.on('error', (err) => {
throw err;
res.status(500).send({ error: err.message });
});
archive.on('finish', () => {
console.log("zip file generate");
});
archive.pipe(zipFile);
archive.pipe(res);
res.on('close', (err) => {
if (err) {
throw err;
}
console.log('Archive wrote %d bytes', archive.pointer());
})
archive.append(fs.createReadStream(englishFilePath), { name: englishFileName });
archive.append(fs.createReadStream(spanishFilePath), { name: spanishFileName });
archive.finalize();
это мой vuejs код для загрузки zip-файла
const url = window.URL.createObjectURL(new Blob([res.body]));
const link = document.createElement("a");
link.setAttribute('href', URL)
link.href = url;
link.setAttribute("download", zipfileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
Теперь я могу скачать zip-файл, но он был поврежден.