-
Notifications
You must be signed in to change notification settings - Fork 1
/
hyper_thread_downloader_example.dart
71 lines (68 loc) · 2.29 KB
/
hyper_thread_downloader_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'dart:io';
import 'package:hyper_thread_downloader/hyper_thread_downloader.dart';
import 'package:hyper_thread_downloader/src/util/log_util.dart';
import 'package:hyper_thread_downloader/src/util/string_util.dart';
void main() async {
final md = HyperDownload();
int taskId = -1;
final url =
'https://updates.cdn-apple.com/2023WinterFCS/fullrestores/032-73564/23D75440-B300-4932-8BD7-283C6218FF4E/iPhone_4.7_15.7.6_19H349_Restore.ipsw';
await md.startDownload(
url: url,
savePath: '/Users/cj/Desktop/cache/${url.getDropLastWhile(Platform.pathSeparator)}',
threadCount: Platform.numberOfProcessors,
fileSize: 5000000,
downloadProgress: ({
required double progress,
required double speed,
required double remainTime,
required int count,
required int total,
}) {
HyperLog.log('download progress: $progress, speed: $speed');
},
downloadComplete: () {
HyperLog.log('download complete');
},
downloadFailed: (String reason) {
HyperLog.log('download failed');
},
downloadTaskId: (int id) {
print('start task id: $id');
taskId = id;
},
workingMerge: (bool ret) {
HyperLog.log('working merge: $ret');
},
downloadingLog: (String log) {},
prepareWorking: (bool value) {});
stdin.listen(
(event) {
String e = String.fromCharCodes(event);
if (e.contains('stop')) {
md.stopDownload(id: taskId);
} else if (e.contains('start')) {
md.startDownload(
url: url,
savePath: '/Users/cj/Desktop/cache/${url.getDropLastWhile('/')}',
threadCount: Platform.numberOfProcessors,
downloadProgress: ({
required double progress,
required double speed,
required double remainTime,
required int count,
required int total,
}) {},
downloadComplete: () {},
downloadFailed: (String reason) {},
downloadTaskId: (int id) {
print('start task id: $id');
taskId = id;
},
workingMerge: (bool ret) {},
downloadingLog: (String log) {},
prepareWorking: (bool value) {});
}
},
);
}