fetch¶
Types
- fetch.Error :: enum u8¶
-
- None¶
- Unsupported¶
-
not http, https, or a file; or no libcurl on this platform.
- Missing¶
-
no such file.
- Network¶
-
the connection or transfer failed.
- Timeout¶
- Status¶
-
the server answered with a status other than 2xx.
- Too_Large¶
- fetch.Options :: struct¶
-
Options bound one get. The zero value is the defaults.
- timeout_ms: int¶
-
the whole transfer; 0: 30 seconds; below 0: none.
- max_bytes: int¶
-
0: 64 MiB.
- user_agent: string¶
- fetch.Result :: struct¶
-
Result is what get read, or why it could not. Its data, url, and message are allocated with the allocator given to get, and the caller owns them: destroy frees them.
- data: []u8¶
- url: string¶
-
where the data came from, after redirects.
- status: int¶
-
the HTTP status, or 0 for files.
- message: string¶
-
what went wrong, for a report.
Procedures
- fetch.destroy :: proc(r: ^Result, allocator := context.allocator)¶
-
destroy frees what get allocated for r, with the same allocator, and clears r.
- fetch.get :: proc(location: string, options: Options, allocator := context.allocator) -> Result¶
-
get reads a URL or path, allocating the result with allocator; the caller owns it and frees it with destroy. It fails with an Error in the result, never a panic: a file that is missing, a transfer that fails, times out, answers with a status other than 2xx, or grows beyond max_bytes. It blocks until the transfer ends; threads may call it at once.
Foreign imports
- foreign import fetch.curl "system:curl"¶
-
Availability: Darwin, Linux, FreeBSD, OpenBSD, NetBSD, WASI, JS, Orca, Freestanding.