限速器

This commit is contained in:
2024-02-24 17:10:28 +08:00
parent 3b025e7b3e
commit 27b5d9259f
4 changed files with 258 additions and 148 deletions

View File

@ -62,8 +62,7 @@ class Aria2cManager {
"--save-session=${sessionFile.absolute.path.trim()}",
"--save-session-interval=60",
"--file-allocation=trunc",
// TODO for debug
"--max-overall-download-limit=100k"
"--seed-time=0",
],
workingDirectory: _aria2cDir);
p.stdout.transform(utf8.decoder).listen((event) {
@ -88,4 +87,20 @@ class Aria2cManager {
await Future.delayed(const Duration(milliseconds: 100));
}
}
static int textToByte(String text) {
if (text.length == 1) {
return 0;
}
if (int.tryParse(text) != null) {
return int.parse(text);
}
if (text.endsWith("k")) {
return int.parse(text.substring(0, text.length - 1)) * 1024;
}
if (text.endsWith("m")) {
return int.parse(text.substring(0, text.length - 1)) * 1024 * 1024;
}
return 0;
}
}