Skip to content

Conversation

@patrickkabwe
Copy link
Owner

@patrickkabwe patrickkabwe commented Nov 16, 2025

Summary

This PR adds support for cancelling upload and download operations by returning a jobId from both uploadFile and downloadFile methods.

Usage Example

// Upload with cancellation
const uploadJobId = await NitroFS.uploadFile(file, options, (uploaded, total) => {
  console.log(`Progress: ${uploaded / total * 100}%`)
})
// Cancel if needed
const cancelled = await NitroFS.cancelUpload(uploadJobId)

// Download with cancellation
const { jobId, file } = await NitroFS.downloadFile(url, destPath, (downloaded, total) => {
  console.log(`Progress: ${downloaded / total * 100}%`)
})
// Cancel if needed (before completion)
const cancelled = await NitroFS.cancelDownload(jobId)

Testing

  • Test upload cancellation
  • Test download cancellation
  • Test concurrent uploads/downloads
  • Test progress callbacks work correctly
  • Test error handling

- Add cancelUpload and cancelDownload methods that return boolean
- Update uploadFile to return jobId immediately for cancellation support
- Update downloadFile to return NitroDownloadResult with jobId and file
- Fix race conditions in iOS uploader and downloader by using sync for state initialization
- Add proper state management for tracking upload/download jobs on both platforms
- Ensure progress callbacks work reliably with proper thread-safe state access
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/upload-download-cancellation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Remove duplicate NitroDownloadResult definitions
- Use generated NitroDownloadResult from nitrogen on both platforms
- Fix return type mismatch in Android HybridNitroFS
- Fix return type mismatch in iOS HybridNitroFs
- Store upload continuations to propagate errors to callers
- Implement didCompleteWithError delegate method to handle errors
- Check HTTP response status codes and throw errors for non-2xx responses
- Handle cancellation errors properly
- Remove continuation immediately to prevent double-resume
- Fix race condition by ensuring state initialization before task resume
- Upload now waits for completion and properly propagates errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants