在http模块中 我chunk下载文件 然后创建文件夹把文件存在文件夹里
http.get(src,(res)=>{
res.on('data',(chunk)=>{
file += chunk;
})
res.on('end',()=>{
var filep = Math.random();
if(!fs.existsSync(filep)){ //每个文件创建一个文件夹
var creats = fs.mkdirSync(filep);
}
fs.writeFile(filep+'a.mp4',file,(err)=>{
if (err) throw err;
});
})
})
但在request模块里
request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
这种方式 我无法创建文件夹 存储文件 我应当 如何在request 完成如上http模块类似的操作
After trying it, it seems that the path to createWriteStream must exist and the folder will not be created. Or should I not put it in the pipe to create the folder? Generate it in advance
Before creating the file, check if the folder exists and create it if it does not exist. Then make a request