Skip to content

An open-source cross-platform alternative to AirDrop

fix: Close file stream properly (#1228)

NightFeather72121eff10a9
diff --git a/app/lib/provider/network/send_provider.dart b/app/lib/provider/network/send_provider.dart
index 616d7aae..534d3ee1 100644
--- a/app/lib/provider/network/send_provider.dart
+++ b/app/lib/provider/network/send_provider.dart
@@ -282,7 +282,7 @@ class SendNotifier extends Notifier<Map<String, SendSessionState>> {
'Content-Type': file.file.lookupMime(),
},
),
- data: file.path != null ? File(file.path!).openRead() : Stream.fromIterable([file.bytes!]),
+ data: file.path != null ? File(file.path!).openRead().asBroadcastStream() : file.bytes!,
onSendProgress: (curr, total) {
if (stopwatch.elapsedMilliseconds >= 100) {
stopwatch.reset();
diff --git a/app/lib/provider/network/server/controller/send_controller.dart b/app/lib/provider/network/server/controller/send_controller.dart
index bf9973b1..fe20181e 100644
--- a/app/lib/provider/network/server/controller/send_controller.dart
+++ b/app/lib/provider/network/server/controller/send_controller.dart
@@ -199,7 +199,7 @@ class SendController {
} else {
return Response(
200,
- body: File(file.path!).openRead(),
+ body: File(file.path!).openRead().asBroadcastStream(),
headers: headers,
);
}