download method

Future<StorageValue?> download([
  1. String? localRelativePath
])

Download the file on the remote side specified by storageQuery to localRelativePath on the local side.

You can wait in downloading while downloading.

The full path of the cache to download can be obtained as a return value.

storageQueryで指定されたリモート側のファイルをローカル上のlocalRelativePathにダウンロードします。

ダウンロード中はdownloadingで待つことができます。

戻り値としてダウンロード先のキャッシュのフルパスを取得することが出来ます。

Implementation

Future<StorageValue?> download([String? localRelativePath]) async {
  if (_downloadCompleter != null) {
    await downloading;
    return value;
  }
  _downloadCompleter = Completer();
  try {
    final localFile = await storageQuery.adapter.download(
      storageQuery.relativeRemotePath.trimQuery().trimStringRight("/"),
      localRelativePath?.trimQuery().trimStringRight("/"),
    );
    _value = _value?._copyWith(
          local: localFile,
        ) ??
        StorageValue._(
          local: localFile,
        );
    notifyListeners();
    _downloadCompleter?.complete();
    _downloadCompleter = null;
    return _value;
  } catch (e) {
    _downloadCompleter?.completeError(e);
    _downloadCompleter = null;
    rethrow;
  } finally {
    _downloadCompleter?.complete();
    _downloadCompleter = null;
  }
}