← All Modules

fs

Filesystem operations. No require() needed.

Reading & Writing

File Operations

Directory Operations

Metadata

Binary I/O

fs.read_bytes and fs.write_bytes handle files with arbitrary byte content (images, WASM, protobuf, compressed data). Lua strings can hold any bytes, so the returned value works with http.serve() response bodies, base64.encode(), or any other builtin that accepts strings.

-- Copy a binary file
local data = fs.read_bytes("image.png")
fs.write_bytes("copy.png", data)

-- Serve binary files via http.serve()
http.serve(8080, {
  GET = {
    ["/*"] = function(req)
      return { status = 200, body = fs.read_bytes("static" .. req.path) }
    end,
  },
})