nabil6391 / flutter_download_manager

Flutter Download Manager is a Cross-Platform file downloader with resumeable, parallel and batch Download support. Also be notified of download status and progress updates
MIT License
46 stars 29 forks source link

progress error #12

Closed ryan1725 closed 1 year ago

ryan1725 commented 1 year ago

Problem: The task was paused first, then resumed, repeated several times, and the initial progress was found to be wrong when resumed。Restoration progress will start from partialFile.length()

https://user-images.githubusercontent.com/119268786/221539959-e5af41bc-b3b1-41cc-9a46-1ba549c4fd86.mp4

Reason: The reason is that the current progress is not written to the partialFile during the pause。

Sloved may be:

Future<void> download(String url, String savePath, cancelToken,
      {forceDownload = false}) async {
   + var partialFilePath = savePath + partialExtension;
   + late File partialFile;

      - //var partialFilePath = savePath + partialExtension;
      - //var partialFile = File(partialFilePath);
      + partialFile = File(partialFilePath);
----------------------------------------------------------------------------------------------------
catch (e) {
      var task = getDownload(url)!;
      if (task.status.value != DownloadStatus.canceled &&
          task.status.value != DownloadStatus.paused) {
        setStatus(task, DownloadStatus.failed);
        runningTasks--;

        if (_queue.isNotEmpty) {
          _startExecution();
        }
        rethrow;
     // The condition add e instance of CancelToken?if other error, seems to be ok。。。。
      } else if (task.status.value == DownloadStatus.paused) {
        + var ioSink = partialFile.openWrite(mode: FileMode.writeOnlyAppend);
        + var _f = File(partialFilePath + tempExtension);
        + await ioSink.addStream(_f.openRead());
        + await ioSink.close();

      }
    }
nabil6391 commented 1 year ago

Can you create a PR?

ryan1725 commented 1 year ago

Can you create a PR? fixed initial progress error during resume, after multiple pause resumes by xuge2it · Pull Request #13 · nabil6391/flutter_download_manager

lucasjinreal commented 1 year ago

Does it merge?

nabil6391 commented 1 year ago

Released now 0.5.5