
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
A library for nodejs to download http large file in pauseable and resumable way
A library for nodejs to download http large file in pauseable and resumable way
Node >= 8.0
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()
})
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)
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.
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.
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
}
})
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.
Start the task. If you specify the numOfThread
argument, it will concurrently start multiple http request.
Stop the task. We could not stop the task immediately, since we have no method to suspend write task.
Events that may triggered:
Remove the listener of the specific event.
Progress of the task. When the task complete, task.progress is 1.
The structure of task.metadata is:
Copyright (c) 2017-present, Xiaole (Will) Liu
FAQs
A library for nodejs to download http large file in pauseable and resumable way
We found that ledown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.