LeDown
A resumable downloader
A library for nodejs to download http large file in pauseable and resumable way
Prerequisite
Node >= 8.0
Usage
Commonjs
var Task = TaskTask
ES6
await task = Task tasktasktasktaskstart
Documentation
static create(options: TaskOptions): Promise<Task>
Static method on Task class for creating a new download task.
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
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
Copyright (c) 2017-present, Xiaole (Will) Liu