NodeJ的writeStream存储在内存中



我需要用archiver压缩一些文件,然后通过电子邮件发送。在archiver示例中,展示了如何将创建的文件存储到fs,但我需要将其临时存储在内存中才能发送。

有办法做到这一点吗?

sendEmail() {
...
if (filesSize > 5) {
const archive = archiver.create('zip', { zlib: { level: 9 } });
const output = fs.createWriteStream(dest) // Destination should be an in memory variable;

archive.pipe(output)

// Code to subscribe to output and archive events
attachments.forEach(file=> {
archive.file(file.path as string, { name: file.filename as string });
})

archive.finalize();
}
...
}

找到的解决方法是保存文件,通过电子邮件发送,并在操作完成后删除文件。

最新更新