Working with Next.js and trying to set up a route for downloading a zip archive that was created using Archiver.
The issue at hand is: how can I pass Archiver to NextResponse?
Check out the code snippet below:
const filesPath = "./data/files/";
const archive = Archiver('zip', { zlib: { level: 9 } });
GetFilesFromKey(token).forEach((filename) => {
archive.file(filesPath + token + "/" + filename.filename, { name: filename.filename });
});
archive.finalize();
// Need to include the code here that transforms "archive" into "BodyInit"
return new NextResponse(SOME BODY INIT, {
headers: {
'Content-Disposition': `attachment; filename="files.zip"`,
'Content-Type': 'application/octet-stream',
},
});