getStream method
Gets the content of the file at path
.
Implementation
Stream<List<int>> getStream(
PathUri path, {
void Function(double progress)? onProgress,
}) {
final request = get_Request(path);
// ignore: discarded_futures
final response = csrfClient.send(request);
final controller = StreamController<List<int>>();
unawaited(
response.then(
(response) {
final contentLength = response.contentLength;
var downloaded = 0;
response.stream.listen(
(chunk) async {
controller.add(chunk);
downloaded += chunk.length;
if (contentLength != null) {
onProgress?.call(downloaded / contentLength);
}
},
onDone: () {
onProgress?.call(1);
controller.close();
},
);
},
// ignore: avoid_types_on_closure_parameters
onError: (Object error) {
controller.addError(error);
},
),
);
return controller.stream;
}