npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lendownload

v1.0.0

Published

A powerful download manager for Node.js with multi-threaded downloading, speed limiting, pause/resume and progress monitoring

Readme

LenDownload - 强大的 Node.js 下载管理器

LenDownload 是一个功能强大的 Node.js 下载管理器,支持多任务并发下载、分片下载、断点续传、速度限制和进度监控等功能。

功能特性

  • 🚀 多任务并发下载 - 支持同时下载多个文件,可配置最大并发数
  • 🔍 分片下载 - 大文件可分片下载,提高下载速度
  • 断点续传 - 支持从断点继续下载,节省时间和流量
  • 🐢 速度限制 - 支持全局和单个任务的速度限制
  • 📊 进度监控 - 实时显示下载进度、速度等信息
  • 📝 日志记录 - 详细记录下载状态和事件
  • 🔄 任务恢复 - 程序重启后可恢复未完成的下载任务
  • 🎛 任务控制 - 支持暂停、恢复、停止单个或所有任务

安装

npm install lendownload
# 或
yarn add lendownload

快速开始

基本使用

const { DownloadManager } = require('lendownload');

// 创建下载管理器实例
const downloadManager = new DownloadManager({
  maxConcurrent: 3, // 最大并发下载数
  globalSpeedLimit: 1024 * 1024, // 全局限速1MB/s
  defaultDownloadPath: './downloads' // 默认下载目录
});

// 添加下载任务
const taskId = downloadManager.addTask({
  url: 'https://example.com/largefile.zip',
  outputPath: './downloads/file.zip', // 可选,不指定则使用默认目录
  options: {
    chunkSize: 2 * 1024 * 1024, // 分片大小(2MB)
    speedLimit: 512 * 1024, // 单个任务限速512KB/s
    onProgress: (progress) => {
      console.log(`进度: ${progress.progress.toFixed(2)}%`);
    },
    onFinish: (result) => {
      console.log(`下载完成: ${result.path}`);
    },
    onError: (error) => {
      console.error('下载失败:', error.message);
    }
  }
});

// 暂停任务
// downloadManager.pauseTask(taskId);

// 恢复任务
// downloadManager.resumeTask(taskId);

// 停止任务
// downloadManager.stopTask(taskId);

批量添加任务

// 批量添加下载任务
const urls = [
  'https://example.com/file1.zip',
  'https://example.com/file2.zip',
  {
    url: 'https://example.com/file3.zip',
    outputPath: './special-downloads/file3.zip'
  }
];

downloadManager.addTasks(urls);

使用进度监控

const { DownloadManager, ProgressMonitor } = require('lendownload');

const downloadManager = new DownloadManager();
const monitor = new ProgressMonitor(downloadManager);

// 开始监控
monitor.start();

// 添加任务...

// 停止监控
// monitor.stop();

API 文档

DownloadManager

下载管理器主类

构造函数

new DownloadManager(options)

参数:

  • options (Object) - 配置选项
    • maxConcurrent (number) - 最大并发下载数,默认3
    • globalSpeedLimit (number) - 全局限速(字节/秒),默认0(不限速)
    • defaultDownloadPath (string) - 默认下载目录,默认'./downloads'
    • logDir (string) - 日志目录,默认'./download-logs'
    • restoreTasks (boolean) - 是否恢复未完成任务,默认true

方法

  • addTask(task) - 添加单个下载任务
  • addTasks(tasks) - 批量添加下载任务
  • pauseTask(taskId) - 暂停指定任务
  • resumeTask(taskId) - 恢复指定任务
  • stopTask(taskId) - 停止指定任务
  • pauseAll() - 暂停所有任务
  • resumeAll() - 恢复所有任务
  • stopAll() - 停止所有任务
  • setGlobalSpeedLimit(speedLimit) - 设置全局限速(字节/秒)

DownloadTask

单个下载任务类

构造函数

new DownloadTask(url, outputPath, options)

参数:

  • url (string) - 下载URL
  • outputPath (string) - 输出文件路径
  • options (Object) - 配置选项
    • chunkSize (number) - 分片大小(字节),默认1MB
    • maxRetries (number) - 最大重试次数,默认3
    • timeout (number) - 请求超时时间(毫秒),默认30000
    • speedLimit (number) - 速度限制(字节/秒),默认0(不限速)
    • onProgress (Function) - 进度回调
    • onFinish (Function) - 完成回调
    • onError (Function) - 错误回调

方法

  • start() - 开始下载
  • pause() - 暂停下载
  • resume() - 恢复下载
  • stop() - 停止下载

ProgressMonitor

进度监控类

构造函数

new ProgressMonitor(downloadManager)

参数:

  • downloadManager (DownloadManager) - 下载管理器实例

方法

  • start() - 开始监控
  • stop() - 停止监控
  • addTask(taskId, task) - 添加任务到监控
  • removeTask(taskId) - 从监控中移除任务

高级功能

任务恢复

当启用restoreTasks选项时,程序会在启动时自动恢复未完成的下载任务。任务状态会保存在logDir指定的目录中。

const downloadManager = new DownloadManager({
  restoreTasks: true, // 启用任务恢复
  logDir: './custom-logs' // 自定义日志目录
});

清除日志

// 清除所有日志和状态
downloadManager.logger.clearAllLogs();

自定义分片大小

downloadManager.addTask({
  url: 'https://example.com/very-large-file.iso',
  options: {
    chunkSize: 5 * 1024 * 1024 // 5MB分片
  }
});

注意事项

  1. 分片下载需要服务器支持Accept-Ranges
  2. 临时文件会保存在下载目录的.temp子目录中
  3. 日志文件可能会占用一定磁盘空间,定期清理或禁用日志可以减少占用

许可证

MIT © [weberzhang]