download method

  1. @override
Future<LocalFile> download(
  1. String remoteRelativePathOrId, [
  2. String? localRelativePath
])
override

Download the file on the remote side specified in remoteRelativePathOrId to localRelativePath on the local.

Both are passed relative to the root folder on each platform.

Return LocalFile containing the full path of the cache to download and the actual data as the return value.

If localRelativePath is not specified, ensure that only byte data is retrieved.

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

どちらも各プラットフォーム上のルートフォルダに対する相対パスが渡されます。

戻り値としてダウンロード先のキャッシュのフルパスと実データを格納したLocalFileを返してください。

localRelativePathが指定されない場合はバイトデータのみが取得されるようにしてください。

Implementation

@override
Future<LocalFile> download(
  String remoteRelativePathOrId, [
  String? localRelativePath,
]) async {
  final remoteFullPath = await remoteStorage.fetchURI(remoteRelativePathOrId);
  if (!await remoteStorage.exists(remoteFullPath)) {
    throw Exception("File could not be found: $remoteFullPath");
  }
  final bytes = await remoteStorage.read(remoteFullPath);
  if (localRelativePath.isNotEmpty) {
    final localFullPath = await localStorage.fetchURI(localRelativePath!);
    if (await localStorage.exists(localFullPath)) {
      await localStorage.delete(localFullPath);
    }
    await localStorage.write(localFullPath, bytes);
    return LocalFile(path: Uri.parse(localFullPath), bytes: bytes);
  } else {
    return LocalFile(bytes: bytes);
  }
}