From 962102407dff662ad25b55a5f7d7333f36c075aa Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:27 +0200 Subject: [PATCH 1/7] refactor(dynamite,neon,nextcloud): use dart 3.1 utf8.encode as Uint8List While the entire utf8 converter has been switched to Uint8List the type annotation still remains List for this release. Adding the downcast as this behavior is what we need. A future dart release should also change the type annotations triggering a linter rule. see: https://github.com/dart-lang/sdk/issues/52801 Signed-off-by: Nikolas Rimikis --- .../dynamite/lib/src/openapi_builder.dart | 2 +- .../neon/neon/lib/src/pages/settings.dart | 2 +- .../nextcloud/lib/src/api/notes.openapi.dart | 5 +-- packages/nextcloud/lib/src/webdav/client.dart | 40 ++++++++----------- packages/nextcloud/test/webdav_test.dart | 10 ++--- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index d41ea1f2..51780b65 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -541,7 +541,7 @@ class OpenAPIBuilder implements Builder { code.write('if ($parameterName != null) {'); } code.write( - '_body = Uint8List.fromList(utf8.encode(${result.encode(parameterName, mimeType: mimeType)}));', + '_body = utf8.encode(${result.encode(parameterName, mimeType: mimeType)}) as Uint8List;', ); if (dartParameterNullable) { code.write('}'); diff --git a/packages/neon/neon/lib/src/pages/settings.dart b/packages/neon/neon/lib/src/pages/settings.dart index 8baf90f7..6e359391 100644 --- a/packages/neon/neon/lib/src/pages/settings.dart +++ b/packages/neon/neon/lib/src/pages/settings.dart @@ -260,7 +260,7 @@ class _SettingsPageState extends State { ), ), ); - await saveFileWithPickDialog(fileName, Uint8List.fromList(utf8.encode(data))); + await saveFileWithPickDialog(fileName, utf8.encode(data) as Uint8List); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); diff --git a/packages/nextcloud/lib/src/api/notes.openapi.dart b/packages/nextcloud/lib/src/api/notes.openapi.dart index 2945461a..6fbd34cd 100644 --- a/packages/nextcloud/lib/src/api/notes.openapi.dart +++ b/packages/nextcloud/lib/src/api/notes.openapi.dart @@ -336,9 +336,8 @@ class NotesClient extends DynamiteClient { } // coverage:ignore-end headers['Content-Type'] = 'application/json'; - body = Uint8List.fromList( - utf8.encode(json.encode(_jsonSerializers.serialize(settings, specifiedType: const FullType(NotesSettings)))), - ); + body = utf8.encode(json.encode(_jsonSerializers.serialize(settings, specifiedType: const FullType(NotesSettings)))) + as Uint8List; final response = await doRequest( 'put', Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(), diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index 88a10b53..9f98a966 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -247,13 +247,11 @@ class WebDavClient { 'PROPFIND', _constructPath(path), data: Stream.value( - Uint8List.fromList( - utf8.encode( - WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()) - .toXmlElement(namespaces: namespaces) - .toXmlString(), - ), - ), + utf8.encode( + WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()) + .toXmlElement(namespaces: namespaces) + .toXmlString(), + ) as Uint8List, ), headers: { if (depth != null) ...{ @@ -277,14 +275,12 @@ class WebDavClient { 'REPORT', _constructPath(path), data: Stream.value( - Uint8List.fromList( - utf8.encode( - WebDavOcFilterFiles( - filterRules: filterRules, - prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line - ).toXmlElement(namespaces: namespaces).toXmlString(), - ), - ), + utf8.encode( + WebDavOcFilterFiles( + filterRules: filterRules, + prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line + ).toXmlElement(namespaces: namespaces).toXmlString(), + ) as Uint8List, ), ), ); @@ -304,14 +300,12 @@ class WebDavClient { 'PROPPATCH', _constructPath(path), data: Stream.value( - Uint8List.fromList( - utf8.encode( - WebDavPropertyupdate( - set: set != null ? WebDavSet(prop: set) : null, - remove: remove != null ? WebDavRemove(prop: remove) : null, - ).toXmlElement(namespaces: namespaces).toXmlString(), - ), - ), + utf8.encode( + WebDavPropertyupdate( + set: set != null ? WebDavSet(prop: set) : null, + remove: remove != null ? WebDavRemove(prop: remove) : null, + ).toXmlElement(namespaces: namespaces).toXmlString(), + ) as Uint8List, ), ); final data = await _parseResponse(response); diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index bf6ac30b..b9080ccb 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -137,7 +137,7 @@ void main() { }); test('Get directory props', () async { - final data = Uint8List.fromList(utf8.encode('test')); + final data = utf8.encode('test') as Uint8List; await client.webdav.mkcol('test'); await client.webdav.put(data, 'test/test.txt'); @@ -169,7 +169,7 @@ void main() { }); test('Filter files', () async { - final response = await client.webdav.put(Uint8List.fromList(utf8.encode('test')), 'test.txt'); + final response = await client.webdav.put(utf8.encode('test') as Uint8List, 'test.txt'); final id = response.headers['oc-fileid']!.first; await client.webdav.proppatch( 'test.txt', @@ -202,7 +202,7 @@ void main() { final uploadTime = DateTime.now(); await client.webdav.put( - Uint8List.fromList(utf8.encode('test')), + utf8.encode('test') as Uint8List, 'test.txt', lastModified: lastModifiedDate, created: createdDate, @@ -237,7 +237,7 @@ void main() { }); test('Remove properties', () async { - await client.webdav.put(Uint8List.fromList(utf8.encode('test')), 'test.txt'); + await client.webdav.put(utf8.encode('test') as Uint8List, 'test.txt'); var updated = await client.webdav.proppatch( 'test.txt', @@ -323,7 +323,7 @@ void main() { ('put_get_utf8_segment', 'res-%e2%82%ac'), ]) { test(name, () async { - final content = Uint8List.fromList(utf8.encode('This is a test file')); + final content = utf8.encode('This is a test file') as Uint8List; final response = await client.webdav.put(content, path); expect(response.statusCode, 201); From 9d243580cb8cde21a2264d2e1bde4b17535dc4cb Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:31 +0200 Subject: [PATCH 2/7] style(nextcloud): cleanup unnecessary cast Signed-off-by: Nikolas Rimikis --- packages/nextcloud/lib/src/client.dart | 5 +---- packages/nextcloud/lib/src/webdav/client.dart | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/nextcloud/lib/src/client.dart b/packages/nextcloud/lib/src/client.dart index 278c47be..f3fb95be 100644 --- a/packages/nextcloud/lib/src/client.dart +++ b/packages/nextcloud/lib/src/client.dart @@ -27,10 +27,7 @@ class NextcloudClient extends DynamiteClient { final String? userAgentOverride, super.cookieJar, }) : super( - baseHeaders: ({ - 'Accept-Language': language, - }..removeWhere((final _, final value) => value == null)) - .cast(), + baseHeaders: language != null ? {'Accept-Language': language} : null, userAgent: userAgentOverride ?? appType.userAgent, authentications: [ if (appPassword != null) ...[ diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index 9f98a966..b08d4dfd 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -103,8 +103,8 @@ class WebDavClient { 'OPTIONS', _constructPath(), ); - final davCapabilities = response.headers['dav']?.cast().first ?? ''; - final davSearchCapabilities = response.headers['dasl']?.cast().first ?? ''; + final davCapabilities = response.headers['dav']?.first ?? ''; + final davSearchCapabilities = response.headers['dasl']?.first ?? ''; return WebDavOptions( davCapabilities.split(',').map((final e) => e.trim()).where((final e) => e.isNotEmpty).toSet(), davSearchCapabilities.split(',').map((final e) => e.trim()).where((final e) => e.isNotEmpty).toSet(), From d072c91ff1a914dc1ae9a922d44029949bd3afe8 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:31 +0200 Subject: [PATCH 3/7] style(nextcloud): cleaup header map handling Signed-off-by: Nikolas Rimikis --- packages/nextcloud/lib/src/webdav/client.dart | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index b08d4dfd..cb8185a7 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -33,8 +33,8 @@ class WebDavClient { for (final header in { HttpHeaders.contentTypeHeader: 'application/xml', ...?rootClient.baseHeaders, - if (headers != null) ...headers, - if (rootClient.authentications.isNotEmpty) ...rootClient.authentications.first.headers, + ...?headers, + ...?rootClient.authentications.firstOrNull?.headers, }.entries) { request.headers.add(header.key, header.value); } @@ -78,24 +78,16 @@ class WebDavClient { Future _parseResponse(final HttpClientResponse response) async => WebDavMultistatus.fromXmlElement(xml.XmlDocument.parse(await response.body).rootElement); - Map? _getUploadHeaders({ + Map _getUploadHeaders({ required final DateTime? lastModified, required final DateTime? created, required final int? contentLength, - }) { - final headers = { - if (lastModified != null) ...{ - 'X-OC-Mtime': (lastModified.millisecondsSinceEpoch ~/ 1000).toString(), - }, - if (created != null) ...{ - 'X-OC-CTime': (created.millisecondsSinceEpoch ~/ 1000).toString(), - }, - if (contentLength != null) ...{ - 'Content-Length': contentLength.toString(), - }, - }; - return headers.isNotEmpty ? headers : null; - } + }) => + { + if (lastModified != null) 'X-OC-Mtime': (lastModified.millisecondsSinceEpoch ~/ 1000).toString(), + if (created != null) 'X-OC-CTime': (created.millisecondsSinceEpoch ~/ 1000).toString(), + if (contentLength != null) HttpHeaders.contentLengthHeader: contentLength.toString(), + }; /// Gets the WebDAV capabilities of the server. Future options() async { @@ -253,11 +245,7 @@ class WebDavClient { .toXmlString(), ) as Uint8List, ), - headers: { - if (depth != null) ...{ - 'Depth': depth.value, - }, - }, + headers: depth != null ? {'Depth': depth.value} : null, ), ); From 52e6ef96f562fc69f11ae511f150a3bce94811f5 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:31 +0200 Subject: [PATCH 4/7] refactor(nextcloud): use avoid creating unnecessary streams Signed-off-by: Nikolas Rimikis --- packages/nextcloud/lib/src/webdav/client.dart | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index cb8185a7..6eb94583 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -22,9 +22,12 @@ class WebDavClient { Future _send( final String method, final String url, { - final Stream? data, + final Stream? dataStream, + final Uint8List? data, final Map? headers, }) async { + assert(dataStream == null || data == null, 'Only one of dataStream or data can be specified.'); + final request = await HttpClient().openUrl( method, Uri.parse(url), @@ -40,7 +43,10 @@ class WebDavClient { } if (data != null) { - await request.addStream(data); + request.add(data); + } + if (dataStream != null) { + await request.addStream(dataStream); } final response = await request.close(); @@ -130,12 +136,15 @@ class WebDavClient { final DateTime? lastModified, final DateTime? created, }) => - putStream( - Stream.value(localData), - path, - lastModified: lastModified, - created: created, - contentLength: localData.lengthInBytes, + _send( + 'PUT', + _constructPath(path), + data: localData, + headers: _getUploadHeaders( + lastModified: lastModified, + created: created, + contentLength: null, + ), ); /// Puts a new file at [path] with [localData] as content. @@ -154,7 +163,7 @@ class WebDavClient { _send( 'PUT', _constructPath(path), - data: localData, + dataStream: localData, headers: _getUploadHeaders( lastModified: lastModified, created: created, @@ -238,13 +247,9 @@ class WebDavClient { await _send( 'PROPFIND', _constructPath(path), - data: Stream.value( - utf8.encode( - WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()) - .toXmlElement(namespaces: namespaces) - .toXmlString(), - ) as Uint8List, - ), + data: utf8.encode( + WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()).toXmlElement(namespaces: namespaces).toXmlString(), + ) as Uint8List, headers: depth != null ? {'Depth': depth.value} : null, ), ); @@ -262,14 +267,12 @@ class WebDavClient { await _send( 'REPORT', _constructPath(path), - data: Stream.value( - utf8.encode( - WebDavOcFilterFiles( - filterRules: filterRules, - prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line - ).toXmlElement(namespaces: namespaces).toXmlString(), - ) as Uint8List, - ), + data: utf8.encode( + WebDavOcFilterFiles( + filterRules: filterRules, + prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line + ).toXmlElement(namespaces: namespaces).toXmlString(), + ) as Uint8List, ), ); @@ -287,14 +290,12 @@ class WebDavClient { final response = await _send( 'PROPPATCH', _constructPath(path), - data: Stream.value( - utf8.encode( - WebDavPropertyupdate( - set: set != null ? WebDavSet(prop: set) : null, - remove: remove != null ? WebDavRemove(prop: remove) : null, - ).toXmlElement(namespaces: namespaces).toXmlString(), - ) as Uint8List, - ), + data: utf8.encode( + WebDavPropertyupdate( + set: set != null ? WebDavSet(prop: set) : null, + remove: remove != null ? WebDavRemove(prop: remove) : null, + ).toXmlElement(namespaces: namespaces).toXmlString(), + ) as Uint8List, ); final data = await _parseResponse(response); for (final a in data.responses) { From ed6502697af9af47cc9ba1ffaed575ef1fca8ce8 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:32 +0200 Subject: [PATCH 5/7] perf(nextcloud): use stream based body decoding Signed-off-by: Nikolas Rimikis --- packages/dynamite/dynamite/lib/src/openapi_builder.dart | 4 +--- packages/nextcloud/lib/src/api/core.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/files_sharing.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/news.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/notes.openapi.dart | 4 +--- packages/nextcloud/lib/src/api/notifications.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/provisioning_api.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/settings.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/theming.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/uppush.openapi.dart | 5 +---- packages/nextcloud/lib/src/api/user_status.openapi.dart | 5 +---- packages/nextcloud/lib/src/webdav/client.dart | 2 +- 12 files changed, 12 insertions(+), 43 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index 51780b65..b559f72b 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -144,11 +144,9 @@ class OpenAPIBuilder implements Builder { ), ) ..body = Block.of([ - const Code('final data = await response.bodyBytes;'), - const Code(''), const Code('String body;'), const Code('try {'), - const Code('body = utf8.decode(data);'), + const Code('body = await response.body;'), const Code('} on FormatException {'), const Code("body = 'binary';"), const Code('}'), diff --git a/packages/nextcloud/lib/src/api/core.openapi.dart b/packages/nextcloud/lib/src/api/core.openapi.dart index e041d2e3..a4e7a475 100644 --- a/packages/nextcloud/lib/src/api/core.openapi.dart +++ b/packages/nextcloud/lib/src/api/core.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -34,11 +33,9 @@ class CoreApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/files_sharing.openapi.dart b/packages/nextcloud/lib/src/api/files_sharing.openapi.dart index 03029f14..c71a6ad5 100644 --- a/packages/nextcloud/lib/src/api/files_sharing.openapi.dart +++ b/packages/nextcloud/lib/src/api/files_sharing.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -34,11 +33,9 @@ class FilesSharingApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/news.openapi.dart b/packages/nextcloud/lib/src/api/news.openapi.dart index 187200b5..5e990249 100644 --- a/packages/nextcloud/lib/src/api/news.openapi.dart +++ b/packages/nextcloud/lib/src/api/news.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -34,11 +33,9 @@ class NewsApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/notes.openapi.dart b/packages/nextcloud/lib/src/api/notes.openapi.dart index 6fbd34cd..e4d14928 100644 --- a/packages/nextcloud/lib/src/api/notes.openapi.dart +++ b/packages/nextcloud/lib/src/api/notes.openapi.dart @@ -34,11 +34,9 @@ class NotesApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/notifications.openapi.dart b/packages/nextcloud/lib/src/api/notifications.openapi.dart index 371ab584..be8cbc3c 100644 --- a/packages/nextcloud/lib/src/api/notifications.openapi.dart +++ b/packages/nextcloud/lib/src/api/notifications.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -34,11 +33,9 @@ class NotificationsApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart b/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart index cf0e79d1..0778324e 100644 --- a/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart +++ b/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -34,11 +33,9 @@ class ProvisioningApiApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/settings.openapi.dart b/packages/nextcloud/lib/src/api/settings.openapi.dart index 05315923..51e46cce 100644 --- a/packages/nextcloud/lib/src/api/settings.openapi.dart +++ b/packages/nextcloud/lib/src/api/settings.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_value/built_value.dart'; @@ -32,11 +31,9 @@ class SettingsApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/theming.openapi.dart b/packages/nextcloud/lib/src/api/theming.openapi.dart index aadcdfe8..b4ded87e 100644 --- a/packages/nextcloud/lib/src/api/theming.openapi.dart +++ b/packages/nextcloud/lib/src/api/theming.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -34,11 +33,9 @@ class ThemingApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/uppush.openapi.dart b/packages/nextcloud/lib/src/api/uppush.openapi.dart index 94e15074..e52587e7 100644 --- a/packages/nextcloud/lib/src/api/uppush.openapi.dart +++ b/packages/nextcloud/lib/src/api/uppush.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -33,11 +32,9 @@ class UppushApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/api/user_status.openapi.dart b/packages/nextcloud/lib/src/api/user_status.openapi.dart index d408feab..b52a6b83 100644 --- a/packages/nextcloud/lib/src/api/user_status.openapi.dart +++ b/packages/nextcloud/lib/src/api/user_status.openapi.dart @@ -1,6 +1,5 @@ // ignore_for_file: camel_case_types // ignore_for_file: public_member_api_docs -import 'dart:convert'; import 'dart:typed_data'; import 'package:built_collection/built_collection.dart'; @@ -34,11 +33,9 @@ class UserStatusApiException extends DynamiteApiException { ); static Future fromResponse(final HttpClientResponse response) async { - final data = await response.bodyBytes; - String body; try { - body = utf8.decode(data); + body = await response.body; } on FormatException { body = 'binary'; } diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index 6eb94583..6d1b49b0 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -55,7 +55,7 @@ class WebDavClient { throw DynamiteApiException( response.statusCode, response.responseHeaders, - utf8.decode(await response.bodyBytes), + await response.body, ); } From 3d545a555a26a31fdd149b2a45f7d49f6724fd1c Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:32 +0200 Subject: [PATCH 6/7] perf(dynamite_runtime): avoid unnecessary Uint8List.toList Signed-off-by: Nikolas Rimikis --- packages/dynamite/dynamite_runtime/lib/src/http_client.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dynamite/dynamite_runtime/lib/src/http_client.dart b/packages/dynamite/dynamite_runtime/lib/src/http_client.dart index 53141502..04d49176 100644 --- a/packages/dynamite/dynamite_runtime/lib/src/http_client.dart +++ b/packages/dynamite/dynamite_runtime/lib/src/http_client.dart @@ -140,7 +140,7 @@ class DynamiteClient { request.headers.add(header.key, header.value); } if (body != null) { - request.add(body.toList()); + request.add(body); } if (cookieJar != null) { request.cookies.addAll(await cookieJar!.loadForRequest(uri)); From 198393d4393605f5631a72d2b5f1841df509736e Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:33 +0200 Subject: [PATCH 7/7] perf(nextcloud): read file as Uint8List according to comment by a dart dev: https://stackoverflow.com/questions/73478943/flutter-dart-read-portions-of-file-as-bytes-rather-than-listint#comment129764806_73478943 it will allways return Uint8List Signed-off-by: Nikolas Rimikis --- packages/nextcloud/lib/src/webdav/client.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index 6d1b49b0..87fc020e 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -189,7 +189,7 @@ class WebDavClient { file.openRead().map((final chunk) { uploaded += chunk.length; onProgress?.call(uploaded / fileStat.size); - return Uint8List.fromList(chunk); + return chunk as Uint8List; }), path, lastModified: lastModified,