1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| const fs = require('fs') const request = require('request')
var tsList = '图片地址.png' core = 1
function download(url){ request.head(url,(err,res,body)=>{ console.log(res.statusCode) if(res.statusCode == 200){ request(url).pipe(fs.createWriteStream(__dirname + `/out/pic.jpg`)).on('close',()=>{ console.log(url,'文件下载完成') }) } }) }
async function init(){ for(let n = 0;n < core;n++){ let data = await download(tsList) } return 'start' }
init().then(function(data) { console.log(data); });
|