代码之家  ›  专栏  ›  技术社区  ›  Relm

Firebase函数因存档的“无法处理响应”而失败

  •  0
  • Relm  · 技术社区  · 5 年前

    这是密码。

    const workingDir = join(tmpdir(), 'zip' + +new Date());
    await fs.ensureDir(workingDir);
    const archive = archiver('zip', { zlib: { level: 9 } });
    
    archive.on('warning', function (err) {
        if (err.code === 'ENOENT') {
            console.log('Warning', err);
        } else {
            throw err;
        }
    });
    
    archive.on('error', function (err) {
        console.log('error', err);
        throw err;
    });
    
    res.attachment(+new Date() + '.zip').type('zip');
    
    archive.pipe(res);
    archive.on('end', () => res.end());
    archive.directory(workingDir, false);
    archive.finalize();
    
    0 回复  |  直到 5 年前
    推荐文章