Referencia Zigzkit (SDK consumido)

src/fs.zig

Declaraciones públicas de src/fs.zig (zkit (SDK consumido)).

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

Página generada desde zkit@zkit-0.0.0-_fk2iAa4BQCqGFKJeeY9WvMQClX5kiZQ2iOZrVsxVyyN (src/root.zig). No se edita a mano: bun run docs:gen la regenera y bun run docs:check falla si difiere.

zkit/fs — ficheros sobre descriptores POSIX, sin runtime Io.

std.fs.File/std.fs.cwd() pasaron detrás de std.Io en 0.16. Un daemon con hilos propios no tiene un Io, así que styx tomó prestado el shim de ficheros del fork de quic-zig (quic.sys.File, createFile, openFileRead, readFileAlloc) — una dependencia de sockets usada para abrir ficheros. Este módulo es ese shim, con cuatro arreglos:

  • File.stat usa statx/fstat y devuelve tamaño, tipo e identidad (dev, ino). El shim original medía el tamaño con tres lseek que movían el offset compartido del fd (carrera con cualquier otro hilo que leyese por el mismo descriptor).
  • File.readAt/readAllAt son pread: sin offset compartido, seguros entre hilos sobre el mismo fd.
  • EAGAIN en escritura no es un bucle caliente: devuelve error.WouldBlock (un fd bloqueante nunca lo produce).
  • Todo open lleva O_CLOEXEC: un fork+exec no hereda descriptores.

Rutas: aquí se abren rutas RELATIVAS AL CWD o absolutas, sin política. Para abrir ficheros controlados por un cliente dentro de una raíz (path traversal, symlinks, TOCTOU) usa zkit.safety.fs.Root, que es fd-relativo.

fs.fd_t

const · línea 35

pub const fd_t = posix.fd_t

Sin ///.

fs.max_path_bytes

const · línea 36

pub const max_path_bytes = std.fs.max_path_bytes

Sin ///.

fs.OpenError

const · línea 38

pub const OpenError = error{ FileNotFound, AccessDenied, IsDir, NotDir, NameTooLong, SymLinkLoop, PathAlreadyExists, NoSpaceLeft, SystemResources, ProcessFdQuotaExceeded, SystemFdQuotaExceeded, ReadOn …

Sin ///.

fs.ReadError

const · línea 54

pub const ReadError = error{ InputOutput, AccessDenied, IsDir, WouldBlock, Unexpected }

Sin ///.

fs.WriteError

const · línea 56

pub const WriteError = error{ DiskQuota, NoSpaceLeft, FileTooBig, BrokenPipe, InputOutput, AccessDenied, WouldBlock, Unexpected, }

Sin ///.

fs.StatError

const · línea 67

pub const StatError = error{ AccessDenied, SystemResources, Unexpected }

Sin ///.

fs.Kind

type · línea 69

pub const Kind = enum

Sin ///.

fs.Stat

type · línea 72

pub const Stat = struct

Metadatos de un descriptor abierto.

fs.File

type · línea 85

pub const File = struct

Descriptor de fichero propio. close lo libera; no hay finalizador.

fs.File.close

fn · línea 88

pub fn close(self: File) void

Sin ///.

fs.File.read

fn · línea 93

pub fn read(self: File, dest: []u8) ReadError!usize

Lee hasta dest.len bytes en el offset actual. 0 = EOF.

fs.File.readAt

fn · línea 105

pub fn readAt(self: File, dest: []u8, offset: u64) ReadError!usize

pread: lee en offset sin tocar el offset del descriptor. 0 = EOF.

fs.File.readAllAt

fn · línea 117

pub fn readAllAt(self: File, dest: []u8, offset: u64) ReadError!usize

Lee hasta llenar dest o llegar a EOF desde offset. Devuelve lo leído.

fs.File.writeAll

fn · línea 127

pub fn writeAll(self: File, bytes: []const u8) WriteError!void

Sin ///.

fs.File.writeAllAt

fn · línea 143

pub fn writeAllAt(self: File, bytes: []const u8, offset: u64) WriteError!void

pwrite completo en offset.

fs.File.sync

fn · línea 159

pub fn sync(self: File) WriteError!void

fsync: los datos y metadatos llegan al dispositivo.

fs.File.stat

fn · línea 164

pub fn stat(self: File) StatError!Stat

Sin ///.

fs.statFd

fn · línea 171

pub fn statFd(fd: fd_t) StatError!Stat

stat de un descriptor: statx en Linux (donde std.c.fstat no está declarado para todas las libc), fstat en el resto.

fs.kindOfMode

fn · línea 208

pub fn kindOfMode(mode: u32) Kind

Sin ///.

fs.pathZ

fn · línea 216

pub fn pathZ(path: []const u8, buf: *[max_path_bytes]u8) error{NameTooLong}![:0]const u8

Copia path a buf con terminador NUL.

fs.openRead

fn · línea 224

pub fn openRead(path: []const u8) OpenError!File

Abre un fichero existente para leer.

fs.CreateOptions

type · línea 230

pub const CreateOptions = struct

Sin ///.

fs.createFile

fn · línea 239

pub fn createFile(path: []const u8, opts: CreateOptions) OpenError!File

Crea (o trunca) un fichero para escribir.

fs.createFlags

fn · línea 245

pub fn createFlags(opts: CreateOptions) posix.O

Sin ///.

fs.openRaw

fn · línea 256

pub fn openRaw(dir: fd_t, path: [*:0]const u8, flags: posix.O, mode: posix.mode_t) OpenError!File

openat con el errno traducido. Público para zkit.safety.fs.

fs.mapOpenErrno

fn · línea 267

pub fn mapOpenErrno(e: posix.E) OpenError

Sin ///.

fs.MakeDirError

const · línea 308

pub const MakeDirError = error{ PathAlreadyExists, AccessDenied, FileNotFound, NotDir, NameTooLong, NoSpaceLeft, ReadOnlyFileSystem, Unexpected, }

Sin ///.

fs.MakeDirOptions

type · línea 319

pub const MakeDirOptions = struct

Sin ///.

fs.makeDir

fn · línea 326

pub fn makeDir(path: []const u8, opts: MakeDirOptions) MakeDirError!void

Sin ///.

fs.makeDirAt

fn · línea 332

pub fn makeDirAt(dir: fd_t, z: [*:0]const u8, opts: MakeDirOptions) MakeDirError!void

Sin ///.

fs.ReadFileError

const · línea 352

pub const ReadFileError = OpenError || ReadError || StatError || std.mem.Allocator.Error || error{FileTooBig}

Sin ///.

fs.readFileAlloc

fn · línea 357

pub fn readFileAlloc(gpa: std.mem.Allocator, path: []const u8, max_bytes: usize) ReadFileError![]u8

Lee path entero en memoria nueva de gpa. error.FileTooBig si pasa de max_bytes (comprobado ANTES de reservar y otra vez al leer, por si el fichero crece entre el stat y la lectura).

fs.readFileAllocFd

fn · línea 363

pub fn readFileAllocFd(gpa: std.mem.Allocator, f: File, max_bytes: usize) ReadFileError![]u8

Sin ///.