一个多任务支持断点续传的Node模块,希望大家多多指教。
发布于 8 年前 作者 chengang4505 4620 次浏览 来自 分享

一张测试: [3_D06IX)R}J]%Z9P1DT46Y.png 安装:

npm install repeat-down

GitHub

Usage:

  var path = require('path');
  var RepeatDown = require('repeat-down');
  
  //{maxRun} max tasks in running, {repeatNum} the auto repeat times internally  if a task failed .
  //{timeout} the connection timeout.
  var downloader = new RepeatDown({maxRun: 6, timeout: 5000, repeatNum: 4});
  
  downloader.get({
	  url:'http://download.sublimetext.com/Sublime%20Text%20Build%203103%20x64%20Setup.exe',
	  dest:path.join(__dirname, 'temp', 'test.zip')
  }).get({
	  url:'http://download.sublimetext.com/Sublime%20Text%20Build%203103%20x64%20Setup.exe',
	  dest:path.join(__dirname, 'temp', 'test2.zip')
  }).run(function(percent,task){//percent callback {percent: 0-100}
	  console.log('file:'+task.dest+' : '+percent);
  },function(err,task){//single task callback ,maybe completed or have a error.
	  if(err){
		  console.log('download err :'+task.url);
	  }else{
		  console.log('download complete :'+task.url);
	  }
  },function(errtasks){//all tasks callback,errtasks are array of err task,
	  if(errtasks.length > 1){
		  console.log('failed tasks :'+errtasks.length);
  
		  //you can call this to continue run the errtasks.
		  //downloader.restartErrTasks(errtasks);
	  }else{
		  console.log('all complete.');
	  }
  });

希望大神门多多指教! O(∩_∩)O哈哈~

3 回复

文件重新下载时,楼主这个怎么校验客户端文件的下载位置,也就是说下次下载从什么位置开始?整个文件从新下载还是?介绍下思路~~

@ncuzp 我这处理的比较简单,就根据你传入的dest 文件路径。

@ncuzp 续传是从上次失败的point 继续,首先要这个url是支持断点续传的

回到顶部