From f20802ef4c72431ce9fa2566a069d69d4e52d83b Mon Sep 17 00:00:00 2001 From: Johan Winge Date: Thu, 19 Sep 2024 09:18:49 +0200 Subject: [PATCH] Reject stopped download if resumable is not set --- README.md | 7 ++++--- ios/Downloader.mm | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 206bab80..5e815bfe 100644 --- a/README.md +++ b/README.md @@ -1095,9 +1095,10 @@ function stopDownload(jobId: number): void; ``` **VERIFIED:** Android, iOS. -Aborts a file download job. The partial file will remain on the filesystem, -and the promise returned from the aborted [downloadFile()] call will reject -with an error. +Aborts a file download job. The partial file will remain on the filesystem. +If resume is not supported (Android), or if the `resumable` optional argument +is not set when calling [downloadFile()], the promise returned from the aborted +[downloadFile()] call will reject with an error. - `jobId` — **number** — Download job ID (see [downloadFile()]). ### stopUpload() diff --git a/ios/Downloader.mm b/ios/Downloader.mm index 2167ed76..8c7294be 100644 --- a/ios/Downloader.mm +++ b/ios/Downloader.mm @@ -164,11 +164,9 @@ - (void)stopDownload { if (_task.state == NSURLSessionTaskStateRunning) { [_task cancelByProducingResumeData:^(NSData * _Nullable resumeData) { - if (resumeData != nil) { + if (resumeData != nil && self->_params.resumableCallback) { self.resumeData = resumeData; - if (self->_params.resumableCallback) { - self->_params.resumableCallback(); - } + self->_params.resumableCallback(); } else { NSError *error = [NSError errorWithDomain:@"RNFS" code:0 //used to pass an NSString @"Aborted" here, but it needs an NSInteger