简体   繁体   English

如何在给定多个可下载链接的节点中创建 zip 文件

[英]how to create a zip file in node given multiple downloadable links

I have a node application that contains several downloadable links (when you click on the link a pdf file is downloaded), and these links are dynamically created/populated.我有一个包含几个可下载链接的节点应用程序(当您单击链接时,会下载 pdf 文件),并且这些链接是动态创建/填充的。 I want to implement a feature where we can somehow download all files from these links in one go.我想实现一个功能,我们可以以某种方式从一个 go 中的这些链接下载所有文件。 I presume for this I will somehow need to create a zip file from all these links - would anyone know how to go about this?我想为此我会以某种方式需要从所有这些链接创建一个 zip 文件 - 有人知道如何 go 吗?

you could use the fs and archiver module:您可以使用 fs 和归档器模块:

var fs = require('fs');
var archiver = require('archiver');
var output = fs.createWriteStream('./example.zip');
var archive = archiver('zip', {
    gzip: true,
    zlib: { level: 9 } // Sets the compression level.
});

archive.on('error', function(err) {
  throw err;
});

// pipe archive data to the output file
archive.pipe(output);

// append files
archive.file('/path/to/file0.txt', {name: 'file0-or-change-this-whatever.txt'});
archive.file('/path/to/README.md', {name: 'foobar.md'});

//
archive.finalize();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM