Stacksmith icon indicating copy to clipboard operation
Stacksmith copied to clipboard

Rewrite download command to be "synchronous".

Open uliwitness opened this issue 5 years ago • 3 comments

Like the "go" command pauses script execution to wait for a download and then resumes it afterwards, make the download command work the same way, and maybe even change it into a url "foo:///bar/baz" function.

The command's instruction would start the download, call LEOPauseContext(), and from the download completion block call LEOResumeContext(). When it is then called again, it would see that from the kLEOContextResuming flag and instead of starting another download would return the file contents and/or set the result to any error information.

uliwitness avatar Feb 17 '19 12:02 uliwitness

Note: #89 should be done before this, or can likely be done as part of this.

uliwitness avatar Feb 17 '19 13:02 uliwitness

Open questions: What do we do with headers, progress reporting etc.? Do we keep the download command for that? Do we save the headers & status codes in a local variable the downloads that can be accessed after the url function finishes? Do we call a downloadProgress handler so another part of the script can at least display progress?

uliwitness avatar Feb 17 '19 13:02 uliwitness

Progress reporting could probably done by calling an optional closure, syntax maybe:

put url "http://example.com" for progress take percentage then put "Downloading:" && percentage 
if status of the download is not 200 then
  answer "Error downloading: " && the statusMessage of the download
end if

That way we don't duplicate stuff and can get rid of the download command.

uliwitness avatar May 19 '20 15:05 uliwitness