diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index 9dbf7642..3e965bc8 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/lib/src/openapi_builder.dart @@ -58,9 +58,14 @@ class OpenAPIBuilder implements Builder { ..returns = refer('Future') ..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( diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index f27fa3ee..4347dfca 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/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 get bodyBytes async => - Uint8List.fromList((await toList()).reduce((final value, final element) => [...value, ...element])); + Future 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 get body async => utf8.decode(await bodyBytes); }