buxing 0.1.0 buxing: ^0.1.0 copied to clipboard
A file downloader. Supports resumable downloads, multiple connections, buffering, auto-retry, etc.
A file downloader. Supports resumable downloads, multiple connections, buffering, auto-retry, etc.
Features #
- Resumable downloads.
- Supports multiple connections.
- Auto buffering for less disk writes.
- Auto connection retry via the builtin
RetryClient
.
TODO #
- HTTP redirection support.
Usage #
Install and import this package:
import 'package:buxing/buxing.dart';
A simple task #
void main() async {
var task = Task(
Uri.parse('https://golang.org/dl/go1.17.3.src.tar.gz'), 'go1.17.3.src.tar.gz');
await task.start();
}
Report progress #
Progress events are raised through Task.onProgress
:
task.onProgress = (prog) => print(prog.transferred / prog.total);
Multiple connections #
To enable multiple connections, set the optional worker
param in constructor and pass a ParallelWorker
.
var task = Task(Uri.parse('https://golang.org/dl/go1.17.3.src.tar.gz'),
'go1.17.3.src.tar.gz',
worker: ParallelWorker()); // A `ParallelWorker` enables multiple connections.
By default ParallelWorker
manages concurrency by itself, you can explicitly set the number of concurrent connections:
ParallelWorker(concurrency: 10)
Buffer size #
The defaults are, 200 KB for a single-connection task, 50 KB per connection for a multi-connection task.
To set the buffer size:
// Single-connection task
var task = Task(Uri.parse('URL'), 'FILE',
worker: Worker(bufferSize: 100000)); // 100 KB
// Multi-connection task.
var task = Task(Uri.parse('URL'), 'FILE',
worker: ParallelWorker(bufferSize: 100000)); // 100 KB