From e9a88279e4fcaf5698c1e37055ca579f3a56f912 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Fri, 17 Nov 2023 11:34:29 -0300 Subject: [PATCH] Revert "Update web_io.dart" This reverts commit c22b22fcdf059974b0e64819e002d1a173a0e623. --- lib/src/web/web_io.dart | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/src/web/web_io.dart b/lib/src/web/web_io.dart index ab9599c..932cff8 100644 --- a/lib/src/web/web_io.dart +++ b/lib/src/web/web_io.dart @@ -184,17 +184,13 @@ class WebIO implements ArDriveIO { ); try { - ardriveIODebugPrint('Creating writable stream...'); - final writable = createWriteStream(file.name, { - 'size': totalBytes, + 'size': await file.length, }); final writer = writable.getWriter(); - await for (final chunk in file.openReadStream(0, totalBytes)) { - ardriveIODebugPrint('Writing ${chunk.length} bytes to file...'); - + await for (final chunk in file.openReadStream()) { if (await completerMaybe(finalize) == false) break; await writer.readyFuture; await writer.writeFuture(chunk); @@ -204,25 +200,25 @@ class WebIO implements ArDriveIO { bytesSaved: bytesSaved, totalBytes: totalBytes, ); - - ardriveIODebugPrint('save status: $bytesSaved/$totalBytes'); } - ardriveIODebugPrint('Finished writing to file. Closing file...'); + await writer.readyFuture; - // FIXME: this never ends on Firefox/Safari. - // final finalizeResult = await finalize.future; - // debugPrint('Finalize result: $finalizeResult'); - // if (!finalizeResult) { - // debugPrint('Cancelling saveFileStream...'); - // writer.abort(); - // await writable.abortFuture('Finalize result is false'); - // } else { + ardriveIODebugPrint('writer ready'); - await writer.closeFuture(); - writer.close(); - writer.releaseLock(); - // } + finalize.complete(true); + + final finalizeResult = await finalize.future; + + if (!finalizeResult) { + ardriveIODebugPrint('Cancelling saveFileStream...'); + writer.abort(); + await writable.abortFuture('Finalize result is false'); + } else { + await writer.closeFuture(); + writer.close(); + writer.releaseLock(); + } yield SaveStatus( bytesSaved: bytesSaved,