Browse Source

Merge pull request #141 from provokateurin/fix/empty-body

dynamite,nextcloud: Fix failing on empty body
pull/143/head
Kate 2 years ago committed by GitHub
parent
commit
11335ca782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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>') ..returns = refer('Future<Uint8List>')
..type = MethodType.getter ..type = MethodType.getter
..modifier = MethodModifier.async ..modifier = MethodModifier.async
..lambda = true
..body = const Code( ..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( 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'; part 'nextcloud.openapi.g.dart';
extension HttpClientResponseBody on HttpClientResponse { extension HttpClientResponseBody on HttpClientResponse {
Future<Uint8List> get bodyBytes async => Future<Uint8List> get bodyBytes async {
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]));
}
Future<String> get body async => utf8.decode(await bodyBytes); Future<String> get body async => utf8.decode(await bodyBytes);
} }

Loading…
Cancel
Save