ludic/docs/language/http/http-save_to.md
Orkuncakilkaya 43d5eb5b88 feat(launcher): Process.*, Http.save_to/received/expected, App.window_hide/show
Process.spawn/poll/kill/free - non-blocking child processes with no shell: posix_spawn on
macOS (process.ll), CreateProcessW with MSVC-quoted arguments and no console window on
Windows (process_win.ll), linked only when a program uses Process.*.

Http.save_to streams a response body into a file (NSURLSession with a run-time delegate
class on macOS, the WinHTTP read loop on Windows); Http.received / Http.expected report
progress while it is pending. Freeing a pending request cancels it and parks the slot
until the worker has finished.

App.window_hide / App.window_show take the game's window off the screen and back without
closing it; the run goes on while hidden. Docs, examples, tests and a changeset.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 13:32:23 +03:00

1.9 KiB

id name category kind tokens sig tip order ns member
http-save_to Http.save_to http namespace-method Http.save_to Http.save_to(handle, path) -> void Stream the response body to a file. 16 Http save_to

Makes the response body of an Http.opened request go straight to the file at path as it arrives, instead of into memory — the way to download something large (an update package of hundreds of megabytes) with a progress bar. Call it before Http.send; afterwards it does nothing.

The file is written directly at path, with no temporary name: Http.send creates it (or truncates an existing one), and a failed or cancelled download leaves whatever had arrived. So download to a name of your own such as "x.nupkg.part" and rename it once Http.poll reports a good status — a non-2xx reply's body (an error page) is written to the file too. If the file cannot be created the request finishes with status 0, as does one whose write fails midway (a full disk).

For such a request Http.text is empty (null) and Http.body_len is the number of bytes written. Follow progress with Http.received and Http.expected. Freeing the request while it is pending cancels the download. The transfer asks for no compression (Accept-Encoding: identity) unless the request set that header, so the bytes counted are the bytes on disk. Files are limited to 2 GB.

program Demo {
  entry {
    let h = Http.open("GET", "https://example.com/big.bin")
    Http.save_to(h, "big.bin.part")
    Http.send(h)
  }
}