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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ledown

v1.0.5

Published

A library for nodejs to download http large file in pauseable and resumable way

Downloads

3

Readme

LeDown

A resumable downloader

Build Status Coverage Status npm version

A library for nodejs to download http large file in pauseable and resumable way

Prerequisite

Node >= 8.0

Usage

Commonjs

var Task = require('ledown').Task
Task.create({
  url: 'url',
  downloadPath: 'path'
}).then(function(task) {
  task.on('progress', function(){
    console.log(task.progress)
  })
  task.on('error', function(err) {
    console.log(err)
  })
  task.on('end', function() {
    console.log('end')
  })
  task.start()
})

ES6

import { Task } from 'ledown'
await task = Task.create({
  url: 'url',
  downloadPath: 'path'
})

task.on('progress', () => {
  console.log(task.progress)
})
task.on('error',err => {
  console.log(err)
})
task.on('end', () => {
  console.log('end')
})
task.start()

setTimeout(() => {
  if(task.progress !== 1) {
    task.stop()
      .then(() => {
        task.storeToFile(path.join(__dirname, './task.config'))
      })
  }
}, 1000)

Documentation

static create(options: TaskOptions): Promise<Task>

Static method on Task class for creating a new download task.

type TaskOptions = {
    url: string
    referUrl?: string
    downloadDir?: string
    downloadPath: string
  } | {
    url: string
    referUrl?: string
    downloadDir: string
    downloadPath?: string
  }

You have to specify whether the downloadDir or downloadPath. If you just specify the downloadDir, a random name will be used.

Task.create use HTTP HEAD method to get metadata of the resource. If server respond an error, the returned promise will be rejected.

static restoreFromFile(path: string): Promise<Task>

Restore task from previous task config file. If ether the specified config file or the previous unfinished downloading file not exists, the returned promise will be rejected.

static Task.Error

  • Task.ERROR.ERR_NO_METADATA
  • Task.ERROR.ERR_DISK_IO_WRITE
  • Task.ERROR.ERR_NETWORK
task.on('error', (e) => {
  if(e.message === Task.ERROR.ERR_DISK_IO_WRITE) {
    // write disk error
  } else if(e.message === Task.ERROR.ERR_NETWORK) {
    // download resource error
  }
})

Task#storeToFile(path: string): Promise<void>

Store a task config to specified path. IO error will cause the returned promise to be rejected. This method will not stop the task. You could call task.stop() as needed.

Task#start(numOfThread: number = 1): void

Start the task. If you specify the numOfThread argument, it will concurrently start multiple http request.

Task#stop(): Promise<void>

Stop the task. We could not stop the task immediately, since we have no method to suspend write task.

Task#on(event: string, listener: function): void

Events that may triggered:

  • on('error')
  • on('progress')
  • on('end')

Task#off(event: string, listener: function): void

Remove the listener of the specific event.

Task#progress: number

Progress of the task. When the task complete, task.progress is 1.

Task#metadata

The structure of task.metadata is:

  • url: string
  • createDate: Date
  • mimeType: string
  • downloadPath: string
  • totalBytes: number
  • resumable: boolean

LICENSE

MIT

Copyright (c) 2017-present, Xiaole (Will) Liu