Referencia Zigconduit-zig (SDK consumido)

zig/client.zig

Declaraciones públicas de zig/client.zig (conduit-zig (SDK consumido)).

ImplementadoSin versión del tren todavía· generada desde apps/docs/generated/zig/conduit.json

Página generada desde conduit@conduit-0.1.0-f7J_7zg5DwCsHBHItwdOz9ZVq8cvH7ceFsk7-m3-T61t (zig/root.zig). No se edita a mano: bun run docs:gen la regenera y bun run docs:check falla si difiere.

The upload state machine (spec §6), sans-IO.

The machine never touches a file or a socket. The host loops:

while (true) switch (up.poll()) { .control => |c| { send up.controlRequest(c, &buf); up.onControlResponse(status, body) }, .read => |r| { bytes = read(file, r.offset, r.len); const t = try up.onChunkData(r.index, bytes); if (t.send) { POST t.request; up.onChunkResponse(r.index, status, body) } }, .wait => wait for an outstanding request, .done, .failed => break, }

so the same machine drives the Zig CLI (threads + std.http), Swift (URLSession, via the C-ABI), Bun (FFI) and the web (WASM). All decisions — chunk plan, window, retries, resume reconciliation, hashing — live here once; the wire codec is wire.zig.

Hashing is streaming and every byte is hashed once per read.

  • wire v1: onChunkData must be called for fresh chunks in index order (the order poll hands them out); the file SHA-256 is fed there, the chunk SHA-256 goes into Content-Digest (two SHA-256 per byte: the wire's cost).
  • wire v2 (Options.protocol = .v2, spec/wire-v2.md): each chunk is a power-of-two subtree of the file's BLAKE3 tree; its chaining value goes into Conduit-Chunk-Cv and the root (b3sum of the file) is the combination of the CVs — one BLAKE3 pass per byte, chunks in any order. Negotiated: a server that does not answer "protocol":2 speaks v1 and the machine continues in v1 (nothing was hashed yet).

A re-read (retry) whose digest differs from the first read fails the upload with source_changed instead of sending different bytes under the same index.

client.Mode

type · línea 43

pub const Mode = enum

Sin ///.

client.Protocol

type · línea 51

pub const Protocol = enum

Sin ///.

client.Options

type · línea 53

pub const Options = struct

Sin ///.

client.Purpose

type · línea 81

pub const Purpose = enum

Sin ///.

client.ChunkRef

type · línea 90

pub const ChunkRef = struct

Sin ///.

client.ControlKind

type · línea 100

pub const ControlKind = enum

Sin ///.

client.Action

type · línea 102

pub const Action = union

Sin ///.

client.FailureKind

type · línea 110

pub const FailureKind = enum

Sin ///.

client.Failure

type · línea 127

pub const Failure = struct

Sin ///.

client.Request

type · línea 134

pub const Request = struct

Sin ///.

client.RequestBuf

type · línea 151

pub const RequestBuf = struct

Storage for a Request (paths, headers, JSON). Owned by the host, so the request stays valid while the host sends it — even across threads.

client.Ticket

type · línea 160

pub const Ticket = struct

Sin ///.

client.Progress

type · línea 171

pub const Progress = struct

Sin ///.

client.EventError

const · línea 178

pub const EventError = error{ /// The host called an event that does not match the machine's state /// (wrong index, wrong length, no such outstanding request). InvalidEvent, /// A fresh chunk was del …

Sin ///.

client.Upload

type · línea 190

pub const Upload = struct

Sin ///.

client.Upload.InitError

const · línea 238

pub const InitError = wire.PlanError || wire.ParseError || Allocator.Error || error{InvalidOptions}

Sin ///.

client.Upload.init

fn · línea 242

pub fn init(gpa: Allocator, opts: Options, resume_id: ?wire.UploadId) InitError!Upload

resume_id: the uploadId of an earlier run (persisted by the host). The machine probes it first and falls back to a new session on 404.

client.Upload.deinit

fn · línea 288

pub fn deinit(self: *Upload) void

Sin ///.

client.Upload.uploadId

fn · línea 302

pub fn uploadId(self: *const Upload) ?wire.UploadId

Sin ///.

client.Upload.failureInfo

fn · línea 306

pub fn failureInfo(self: *const Upload) ?Failure

Sin ///.

client.Upload.sha256

fn · línea 311

pub fn sha256(self: *const Upload) ?wire.Digest

SHA-256 of the uploaded file, when it finished in wire v1.

client.Upload.root

fn · línea 316

pub fn root(self: *const Upload) ?tree.Cv

BLAKE3 root of the uploaded file (b3sum), when it finished in wire v2.

client.Upload.protocol

fn · línea 322

pub fn protocol(self: *const Upload) Protocol

The wire the session speaks (final once the server answered create or the resume probe).

client.Upload.setConcurrency

fn · línea 345

pub fn setConcurrency(self: *Upload, n: u16) void

Chunks the host may have being read or sent from now on, clamped to [1, opts.concurrency]. Lowering it does not cancel what is in flight; poll just hands out fewer until it is under the new limit.

client.Upload.refuseEncodings

fn · línea 352

pub fn refuseEncodings(self: *Upload) void

Stop offering content-codings (the host's policy found the payload not worth encoding: media, already compressed, or it does not shrink). Valid before the create request is sent.

client.Upload.finalPath

fn · línea 358

pub fn finalPath(self: *const Upload) ?[]const u8

Server key of the finished file (finalPath), valid until deinit.

client.Upload.progress

fn · línea 362

pub fn progress(self: *const Upload) Progress

Sin ///.

client.Upload.poll

fn · línea 376

pub fn poll(self: *Upload) Action

Sin ///.

client.Upload.onChunkData

fn · línea 497

pub fn onChunkData(self: *Upload, index: u32, bytes: []const u8, buf: *RequestBuf) EventError!Ticket

The host read chunk index (the bytes of poll's .read). Returns the request to send when ticket.send; buf must outlive the send.

client.Upload.onChunkHashed

fn · línea 529

pub fn onChunkHashed(self: *Upload, index: u32, len: u64, node: tree.Node, buf: *RequestBuf) EventError!Ticket

wire v2, for hosts that hash outside their lock (the driver's workers do, so chunks hash on every core): the chunk's node from chunkNode, computed on the bytes of poll's .read. Same effect as onChunkData with those bytes.

client.Upload.chunkNode

fn · línea 552

pub fn chunkNode(plan: wire.Plan, index: u32, bytes: []const u8) tree.Node

The node of chunk index in the file's BLAKE3 tree (wire v2): one pass over its bytes as a subtree at its offset (an aligned power of two, so its CV is a node of the file's tree). Pure; any thread.

client.Upload.onChunkResponse

fn · línea 607

pub fn onChunkResponse(self: *Upload, index: u32, status: u16, body: []const u8) EventError!void

Response to a chunk POST (status 0 = transport error: no response).

client.Upload.controlRequest

fn · línea 656

pub fn controlRequest(self: *Upload, kind: ControlKind, buf: *RequestBuf) Request

Sin ///.

client.Upload.onControlResponse

fn · línea 693

pub fn onControlResponse(self: *Upload, status: u16, body: []const u8) EventError!void

Response to the outstanding control request (status 0 = transport error).