2 Star 10 Fork 4

罗世明/auto-code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
down-file.js 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
lsm 提交于 2023-08-09 15:26 . script init
/**
* 下载文件
*/
const axios = require('axios');
const url = require('url');
const fs = require('fs-extra');
const path = require('path');
async function startDownFile(url, out_path, opts = {}) {
let file_stream = await axios.get(url, {
responseType: 'stream',
headers: {}
});
await new Promise((resolve, reject) => {
fs.ensureFileSync(out_path);
let writer = fs.createWriteStream(out_path);
// let img_size = Number(file_stream.headers['content-length']);
// let progress_bar = false;
writer.on('finish', resolve);
writer.on('error', reject);
// 推流
file_stream.data.pipe(writer);
});
console.log(`Download Success.`);
}
let fileList = [
'http://www.oct-huanleli-cd.cn/js/baseCheck.js?ts=4',
'http://www.oct-huanleli-cd.cn/js/Data.js'
];
// run
(async () => {
for (let i = 0, tmp; i < fileList.length; i++) {
tmp = fileList[i];
let url_pathname = url.parse(tmp)?.pathname;
await startDownFile(tmp, path.join(__dirname, 'auto-script/tmp', path.basename(url_pathname)));
}
})();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gitfuck99/auto-code.git
git@gitee.com:gitfuck99/auto-code.git
gitfuck99
auto-code
auto-code
master

搜索帮助