Skip to content

Net

HTTP, off the caller’s thread. Each host it talks to, redirects too, has to be in “permissions”: { “net”: […] } in its wraith.json.

Get it with Api.net().

fetch(request: import("salamander").Given<Wraith.Net.Request>): Promise<Wraith.Net.Response>
download(request: import("salamander").Given<Wraith.Net.Request>, path: string): Promise<bigint>
downloading(path: string): Wraith.Net.Progress

Settles with any status, so check it. Follows up to 5 redirects.

Async. Fails with NetError. Uses Net.Request, Net.Response.

Streams the body to path, replacing what’s there once it’s all in, and settles with its size. Relative paths are in its folder for this game.

Async. Fails with NetError. Uses Net.Request.

How its download to path is going, for drawing progress. Any thread.

Uses Net.Progress.

What can go wrong, besides Cancelled, Unsupported and Gone.

Code Error
1 Failed Couldn’t connect, or the connection broke
2 NotDeclared Its host, or one it redirects to, isn’t in “permissions”: { “net”: […] }
3 InvalidUrl Not an http:// or https:// URL
4 TooBig Longer than max_bytes
5 Status For download, when the server says no, like 404. fetch gives the status instead
6 WriteFailed For download: couldn’t write there, or it’s outside its folders without “files”
7 Timeout Nothing arrived for timeout_ms

An enum of u8.

Value Name
0 get
1 head
2 post
3 put
4 patch
5 delete

A struct, 0x20 bytes, aligned to 8.

Offset Field Type
0x0 name string
0x10 value string
name: string
value: string

A struct, 0x48 bytes, aligned to 8.

Offset Field Type
0x0 url string
0x10 method Net.Method
0x18 headers []Net.Header
0x28 body []u8 Sent with a content-length, for post, put and patch
0x38 max_bytes u64 0 for the most fetch keeps, 64 MiB. Downloads have no limit unless they say
0x40 timeout_ms u32 How long it waits with nothing arriving, so a slow download still finishes. 0 for 30 s
url: string
method: Wraith.Net.Method | Wraith.Net.MethodName
headers: Array<Wraith.Net.Header>
body: Array<number>
max_bytes: bigint
timeout_ms: number

A struct, 0x28 bytes, aligned to 8.

Offset Field Type
0x0 status u16
0x8 headers []Net.Header
0x18 body blob
status: number
headers: Array<Wraith.Net.Header>
body: Uint8Array | null

A struct, 0x18 bytes, aligned to 8.

Offset Field Type
0x0 received u64
0x8 total u64 0 if the server didn’t say
0x10 active bool False before it starts and once it’s done
received: bigint
total: bigint
active: boolean

Made with ♥ by Asgard