getFileStream method

  1. @override
Stream<FileResponse> getFileStream(
  1. String url, {
  2. String? key,
  3. Map<String, String>? headers,
  4. bool withProgress = false,
})
override

Get the file from the cache and/or online, depending on availability and age.

Downloaded from url, headers can be used for example for authentication. The files are returned as a stream. First the cached file if available, when the cached file is too old the newly downloaded file is returned afterwards.

The FileResponse is either a FileInfo object for fully downloaded files or a DownloadProgress object for when a file is being downloaded. The DownloadProgress objects are only dispatched when withProgress is set on true and the file is not available in the cache.

Implementation

@override
Stream<FileResponse> getFileStream(
  String url, {
  String? key,
  Map<String, String>? headers,
  bool withProgress = false,
}) {
  final controller = StreamController<FileResponse>();
  _pushFileToStream(controller, url, key ?? url, headers, withProgress);
  return controller.stream;
}