Javascript node.js webtorrent通过磁铁链接收集所有文件
我以前没有使用过node.js。Javascript node.js webtorrent通过磁铁链接收集所有文件,javascript,node.js,webtorrent,Javascript,Node.js,Webtorrent,我以前没有使用过node.js。 有一个包含磁铁链接列表的.txt文件。 希望编写一个json文件,其中包含这些链接中包含的所有文件的列表 var WebTorrent = require('webtorrent'); var fs = require('fs'); var client = new WebTorrent(); var array = fs.readFileSync('yop.txt').toString().split("\n"); i = 0; while (i < a
有一个包含磁铁链接列表的.txt文件。 希望编写一个json文件,其中包含这些链接中包含的所有文件的列表
var WebTorrent = require('webtorrent');
var fs = require('fs');
var client = new WebTorrent();
var array = fs.readFileSync('yop.txt').toString().split("\n");
i = 0;
while (i < array.length) {
//console.log(array[i]);
var magnetURI = array[i];
n = 0;
client.add(magnetURI, function (torrent) {
torrent.files.forEach(function (file) {
//console.log( file.name)
jsonString = JSON.stringify({'book': file.name});
fs.appendFile("data.json", jsonString, function (err) {
if (err) {console.log(err);} else { n++ }
});
if (n == torrent.files.length) {i++ }
})
})
var WebTorrent=require('WebTorrent');
var fs=需要('fs');
var client=new WebTorrent();
var array=fs.readFileSync('yop.txt').toString().split(“\n”);
i=0;
while(i
}
很抱歉出现了这么糟糕的代码。您真的应该解释一下您的答案,不鼓励代码转储。
var WebTorrent = require('webtorrent')
var fs = require('fs')
var stream = fs.createWriteStream("2.txt");
var client = new WebTorrent()
var array = fs.readFileSync('yop.txt').toString().split("\n");
i = 0;
function parseMagnet (uri){
var magnetURI = uri[i]
console.log(magnetURI)
client.add(magnetURI, function (torrent) {
torrent.files.forEach(function (file) {
writeStr = (uri[i]+ '\n'+ file.name+ '\n');
stream.write(writeStr);
console.log(file.name)
});
console.log('Done !')
console.log(i)
i += 1
parseMagnet(array);
client.remove(magnetURI);
})
}
parseMagnet(array)