You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
775 B
33 lines
775 B
2 years ago
|
part of '../neon_files.dart';
|
||
3 years ago
|
|
||
|
class DownloadTask {
|
||
|
DownloadTask({
|
||
|
required this.path,
|
||
|
});
|
||
|
|
||
|
final List<String> path;
|
||
|
|
||
|
final _streamController = StreamController<int>();
|
||
|
late final progress = _streamController.stream.asBroadcastStream();
|
||
|
|
||
|
Future execute(final NextcloudClient client, final IOSink sink) async {
|
||
|
final completer = Completer();
|
||
|
|
||
2 years ago
|
final response = await client.webdav.downloadStream(path.join('/'));
|
||
3 years ago
|
var downloaded = 0;
|
||
|
|
||
|
response.listen((final chunk) async {
|
||
|
sink.add(chunk);
|
||
|
|
||
|
downloaded += chunk.length;
|
||
|
_streamController.add((downloaded / response.contentLength * 100).toInt());
|
||
|
|
||
|
if (downloaded >= response.contentLength) {
|
||
|
completer.complete();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return completer.future;
|
||
|
}
|
||
|
}
|