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 🙏

© 2026 – Pkg Stats / Ryan Hefner

xjt870-file-downloader

v1.0.0

Published

File download SDK with progress tracking and state management

Downloads

4

Readme

File Downloader SDK

文件下载SDK,支持断点续传、进度跟踪和状态管理。

安装

npm install xjt870-file-downloader
# 或者
yarn add xjt870-file-downloader
# 或者
pnpm add xjt870-file-downloader

使用

import { VisualDownloadSDK } from 'xjt870-file-downloader';

const sdk = new VisualDownloadSDK({
    userId: 'user123',
    maxConcurrentDownloads: 3,
    onProgress: (progress) => {
        console.log('Download progress:', progress);
    }
});

// 开始下载
await sdk.download({
    taskId: 'file123',
    filename: 'example.pdf',
    fileUrl: 'https://example.com/file.pdf',
    fileSize: 1024 * 1024
});

特性

  • 📦 文件分片下载
  • 🔄 断点续传
  • 📊 进度跟踪
  • 💾 本地存储
  • 🔄 状态管理
  • 🎯 并发控制

快速开始

import VisualDownloadSDK from '@baidu/visual-download-sdk';

// 初始化SDK
const sdk = new VisualDownloadSDK({
    userId: 'user123',
    maxConcurrentDownloads: 3
});

// 创建下载任务
const taskId = await sdk.download({
    taskId: 'file123',
    fileUrl: 'https://example.com/file.zip',
    filename: 'file.zip',
    fileSize: 1024 * 1024 * 10 // 10MB
});

// 监听下载状态
sdk.subscribe((downloadList) => {
    console.log('Download status updated:', downloadList);
});

// 暂停下载
await sdk.pause(taskId);

// 恢复下载
await sdk.resume(taskId);

// 删除任务
await sdk.remove(taskId);

API文档

VisualDownloadSDK

构造函数

constructor(config: SDKConfig)

配置参数:

  • userId: string - 用户标识
  • chunkSize?: number - 分片大小(默认1MB)
  • maxConcurrentDownloads?: number - 最大并发下载数(默认3)
  • onError?: (error: Error) => void - 错误处理回调
  • onProgress?: (progress: TaskProgress) => void - 进度更新回调

方法

download(fileInfo: DownloadFile): Promise

创建下载任务

pause(taskId: string): Promise

暂停指定任务

resume(taskId: string): Promise

恢复指定任务

remove(taskId: string): Promise

删除指定任务

getDownloadList(): TaskMetadata[]

获取下载列表

subscribe(listener: (list: TaskMetadata[]) => void): () => void

订阅下载状态变化

initialize(): Promise

初始化SDK

destroy(): Promise

销毁SDK实例

类型定义

interface DownloadFile {
    taskId: string;
    fileUrl: string;
    filename: string;
    fileSize: number;
    chunkSize?: number;
    dlinkParams?: any;
}

interface TaskMetadata {
    taskId: string;
    filename: string;
    fileLength: number;
    status: string;
    progress: number;
    speed: string;
    error?: string;
}

interface TaskProgress {
    taskId: string;
    loaded: number;
    total: number;
    speed: string;
    progress: number;
}

示例

基础用法

// 初始化SDK
const sdk = new VisualDownloadSDK({
    userId: 'user123'
});

// 创建下载任务
const taskId = await sdk.download({
    taskId: 'file123',
    fileUrl: 'https://example.com/file.zip',
    filename: 'file.zip',
    fileSize: 1024 * 1024 * 10
});

// 监听进度
sdk.subscribe((list) => {
    const task = list.find(t => t.taskId === taskId);
    if (task) {
        console.log(`Download progress: ${task.progress}%`);
    }
});

错误处理

const sdk = new VisualDownloadSDK({
    userId: 'user123',
    onError: (error) => {
        console.error('Download error:', error);
    }
});