fetch method

Future<List<int>> fetch(
  1. String url
)

Implementation

Future<List<int>> fetch(String url) async {
  final network = _client();
  if (network == null) {
    throw const SkinFetchException('Skin download has no network client');
  }
  final NetworkResponse response;
  try {
    response = await network.execute(NetworkRequest(
      url: url,
      method: HttpMethod.get,
      receiveTimeout: const Duration(seconds: 20),
    ));
  } catch (error) {
    throw SkinFetchException('Skin download failed: $error');
  }
  if (!response.isSuccessful) {
    throw SkinFetchException('Skin download HTTP ${response.statusCode}');
  }
  final bytes = utf8.encode(response.body ?? '');
  if (bytes.length > skinFileMaxBytes) {
    throw const SkinFetchException('Skin file over size limit');
  }
  if (bytes.isEmpty) throw const SkinFetchException('Skin file is empty');
  return bytes;
}