在节点应用程序中,我希望下载一个 zip 文件,其中包含从 Internet 上的各种 url 下载的 pdf(如果我在浏览器中输入 url,它只会指示我下载 pdf)。我一直在使用存档器模块,该模块记录在 github 上https://github.com/archiverjs/node-archiver,官方文档位于https://www.archiverjs.com/。
我被困在它提供以下示例以将文件添加到 zip 文件的部分。
// append a file from stream
var file1 = __dirname + '/file1.txt';
archive.append(fs.createReadStream(file1), { name: 'file1.txt' });
// append a file from string
archive.append('string cheese!', { name: 'file2.txt' });
// append a file from buffer
var buffer3 = Buffer.from('buff it!');
archive.append(buffer3, { name: 'file3.txt' });
// append a file
archive.file('file1.txt', { name: 'file4.txt' });
// append files from a sub-directory and naming it `new-subdir` within the archive
archive.directory('subdir/', 'new-subdir');
// append files from a sub-directory, putting its contents at the root of archive
archive.directory('subdir/', false);
// append files from a glob pattern
archive.glob('subdir/*.txt');
不幸的是,似乎只是将 url 粘贴到 .append 或 .directory 的第一个参数中不起作用 - 有人知道我如何将可下载的文件(在线)添加到 zip 文件中吗?