Browse Source

dynamite,nextcloud: Fix failing on empty body

pull/141/head
jld3103 2 years ago
parent
commit
0a81d6f21b
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 9
      packages/dynamite/lib/src/openapi_builder.dart
  2. 10
      packages/nextcloud/lib/src/nextcloud.openapi.dart

9
packages/dynamite/lib/src/openapi_builder.dart

@ -58,9 +58,14 @@ class OpenAPIBuilder implements Builder {
..returns = refer('Future<Uint8List>')
..type = MethodType.getter
..modifier = MethodModifier.async
..lambda = true
..body = const Code(
'Uint8List.fromList((await toList()).reduce((final value, final element) => [...value, ...element]))',
'''
final chunks = await toList();
if (chunks.isEmpty) {
return Uint8List(0);
}
return Uint8List.fromList(chunks.reduce((final value, final element) => [...value, ...element]));
''',
),
),
Method(

10
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -10,8 +10,14 @@ export 'package:cookie_jar/cookie_jar.dart';
part 'nextcloud.openapi.g.dart';
extension HttpClientResponseBody on HttpClientResponse {
Future<Uint8List> get bodyBytes async =>
Uint8List.fromList((await toList()).reduce((final value, final element) => [...value, ...element]));
Future<Uint8List> get bodyBytes async {
final chunks = await toList();
if (chunks.isEmpty) {
return Uint8List(0);
}
return Uint8List.fromList(chunks.reduce((final value, final element) => [...value, ...element]));
}
Future<String> get body async => utf8.decode(await bodyBytes);
}

Loading…
Cancel
Save