Skip to content
jess
api

Files

Files and folders are @dream/fs, L3i's file module: what jess adds is the capability gate and @jess/backup.

Scripts read and write files with @dream/fs, L3i's file module, which every jess runtime has. jess has no file API of its own, on purpose: one module, one error style, one idea of list order. What jess adds is the gate in front of it. Reading needs filesystem.read and changing the disk filesystem.write (jess run --capability, or the capabilities a target declares); joining and taking paths apart needs neither. The Files recipes use it.

A @dream/fs function that fails answers nil, a message naming the path, and a kind, and never raises: wrap the call in assert where a failure should stop the script.

--!strict
local fs = require '@dream/fs'

local manifest = assert(fs.readFileString 'jess.toml')
assert(fs.writeFile('target/manifest.copy.toml', manifest, { atomic = true, createParents = true }))

Three things to know before reaching for it:

  • list(path) is sorted by name, and walk(root, options) covers a whole tree.
  • writeFile writes what it's told and keeps nothing. A tool that overwrites someone's file

should keep what was there, which is @jess/backup.

  • stat(path) has size, modifiedSeconds, and modifiedNanoseconds; there is no separate

size or modified call.

The whole module, with the rest of L3i's primitives, is on L3i's site.