Nikolas Rimikis
1 year ago
8 changed files with 223 additions and 240 deletions
@ -1,34 +0,0 @@ |
|||||||
part of '../neon_files.dart'; |
|
||||||
|
|
||||||
class DownloadTask { |
|
||||||
DownloadTask({ |
|
||||||
required this.path, |
|
||||||
}); |
|
||||||
|
|
||||||
final List<String> path; |
|
||||||
|
|
||||||
final _streamController = StreamController<double>(); |
|
||||||
|
|
||||||
/// Upload progress in percent [0, 1]. |
|
||||||
late final progress = _streamController.stream.asBroadcastStream(); |
|
||||||
|
|
||||||
Future execute(final NextcloudClient client, final IOSink sink) async { |
|
||||||
final completer = Completer(); |
|
||||||
|
|
||||||
final response = await client.webdav.getStream(path.join('/')); |
|
||||||
var downloaded = 0; |
|
||||||
|
|
||||||
response.listen((final chunk) async { |
|
||||||
sink.add(chunk); |
|
||||||
|
|
||||||
downloaded += chunk.length; |
|
||||||
_streamController.add(downloaded / response.contentLength); |
|
||||||
|
|
||||||
if (downloaded >= response.contentLength) { |
|
||||||
completer.complete(); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
return completer.future; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,66 @@ |
|||||||
|
part of '../neon_files.dart'; |
||||||
|
|
||||||
|
sealed class FilesTask { |
||||||
|
FilesTask({ |
||||||
|
required this.path, |
||||||
|
}); |
||||||
|
|
||||||
|
final List<String> path; |
||||||
|
|
||||||
|
@protected |
||||||
|
final streamController = StreamController<double>(); |
||||||
|
|
||||||
|
/// Task progress in percent [0, 1]. |
||||||
|
late final progress = streamController.stream.asBroadcastStream(); |
||||||
|
} |
||||||
|
|
||||||
|
class FilesDownloadTask extends FilesTask { |
||||||
|
FilesDownloadTask({ |
||||||
|
required super.path, |
||||||
|
}); |
||||||
|
|
||||||
|
Future execute(final NextcloudClient client, final IOSink sink) async { |
||||||
|
final completer = Completer(); |
||||||
|
|
||||||
|
final response = await client.webdav.getStream(path.join('/')); |
||||||
|
var downloaded = 0; |
||||||
|
|
||||||
|
response.listen((final chunk) async { |
||||||
|
sink.add(chunk); |
||||||
|
|
||||||
|
downloaded += chunk.length; |
||||||
|
streamController.add(downloaded / response.contentLength); |
||||||
|
|
||||||
|
if (downloaded >= response.contentLength) { |
||||||
|
completer.complete(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
return completer.future; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class FilesUploadTask extends FilesTask { |
||||||
|
FilesUploadTask({ |
||||||
|
required super.path, |
||||||
|
required this.size, |
||||||
|
required this.lastModified, |
||||||
|
}); |
||||||
|
|
||||||
|
final int size; |
||||||
|
final DateTime lastModified; |
||||||
|
|
||||||
|
Future execute(final NextcloudClient client, final Stream<List<int>> stream) async { |
||||||
|
var uploaded = 0; |
||||||
|
await client.webdav.putStream( |
||||||
|
stream.map((final chunk) { |
||||||
|
uploaded += chunk.length; |
||||||
|
streamController.add(uploaded / size); |
||||||
|
|
||||||
|
return Uint8List.fromList(chunk); |
||||||
|
}), |
||||||
|
path.join('/'), |
||||||
|
lastModified: lastModified, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -1,32 +0,0 @@ |
|||||||
part of '../neon_files.dart'; |
|
||||||
|
|
||||||
class UploadTask { |
|
||||||
UploadTask({ |
|
||||||
required this.path, |
|
||||||
required this.size, |
|
||||||
required this.lastModified, |
|
||||||
}); |
|
||||||
|
|
||||||
final List<String> path; |
|
||||||
final int size; |
|
||||||
final DateTime lastModified; |
|
||||||
|
|
||||||
final _streamController = StreamController<double>(); |
|
||||||
|
|
||||||
/// Upload progress in percent [0, 1]. |
|
||||||
late final progress = _streamController.stream.asBroadcastStream(); |
|
||||||
|
|
||||||
Future execute(final NextcloudClient client, final Stream<List<int>> stream) async { |
|
||||||
var uploaded = 0; |
|
||||||
await client.webdav.putStream( |
|
||||||
stream.map((final chunk) { |
|
||||||
uploaded += chunk.length; |
|
||||||
_streamController.add(uploaded / size); |
|
||||||
|
|
||||||
return Uint8List.fromList(chunk); |
|
||||||
}), |
|
||||||
path.join('/'), |
|
||||||
lastModified: lastModified, |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue