Skip to content

Conversation

MohabCodeX
Copy link
Contributor

@MohabCodeX MohabCodeX commented Sep 9, 2025

Warning

This feature has not been fully tested. Please test thoroughly and report any issues or unexpected behaviors. Your feedback is highly appreciated.

Sorry if I may have disappointed you, but this will take time and will need a different solution 🫠

New Functionality

  • abortDownload(handlerId)
    Cancels an ongoing download using a unique handler ID.

The function returns false in these cases:

  • Invalid handler ID (download doesn't exist)
  • Download already completed
  • Download already cancelled
  • HTTP cancellation failed
  • It returns true when the download was successfully cancelled.

Usage Example

local download, handlerId = downloadFile("file.txt")
-- ... later ...
local success = abortDownload(handlerId)

🛠️ Changes

  • Added download tracking using unique handler IDs.
  • Integrated proper cancellation logic with the HTTP manager.
  • Implemented input validation for both downloadFile and abortDownload.
  • memory safety and error handling throughout.

Breaking Changes

  • downloadFile() now returns two values (download object, handler ID) instead of a single boolean.

🔗 Resolves

@Fernando-A-Rocha
Copy link
Contributor

I think new feature PRs are on-hold for now. 1.7 release is waiting for fixes first

Either way, this is cool

@ffsPLASMA
Copy link
Contributor

Thank you for adding this feature, much needed.
If it isnt too much work, could you also add something like:

local numBytesDownloaded, numTotalBytesToDownload = getDownloadProgress(downloadHandler);

Very good addition for UIs to display the download progress.

@MohabCodeX
Copy link
Contributor Author

The main problem is that practical usage is limited due to a fundamental issue with downloadFile.
Currently, downloadFile is blocking (synchronous), it halts script execution until the file is fully downloaded.
This prevents proper asynchronous handling and makes progress tracking ineffective during the actual download.

@MohabCodeX MohabCodeX marked this pull request as draft September 9, 2025 19:01
@FileEX FileEX added the enhancement New feature or request label Sep 13, 2025
@ffsPLASMA
Copy link
Contributor

How feasible would it be to create something like asyncDownloadFile function?

@Fernando-A-Rocha
Copy link
Contributor

How feasible would it be to create something like asyncDownloadFile function?

Why not just make downloadFile not blocking? I think that wouldn't break scripts. It returns true if file to download was queued successfully - is this the slow operation?

@ffsPLASMA
Copy link
Contributor

How feasible would it be to create something like asyncDownloadFile function?

Why not just make downloadFile not blocking? I think that wouldn't break scripts. It returns true if file to download was queued successfully - is this the slow operation?

Yes I see no problem making downloadFile async in general. No one sane would put lua logic after downloadFile call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants