rs-web's rs.assets.write_hashed writes relative to the project root and takes text content, so hash a generated binary file with rs.hash.file, rename and register
FactVerified 1 Oct 2026Holds anywhere
Fact. A statement and the evidence for it.
Statement#
rs.assets.write_hashed(content, path)hashes the content bytes you pass in Lua and writes relative to the project root, notdist/.- The read APIs
rs.fs.readandrs.async.read_fileare text-only, so Lua cannot feed the bytes of an image towrite_hashedwithout rawio. - To give a generated binary file (such as an image variant in
dist/) a content-hashed name: hash its bytes withrs.hash.file, rename it withrs.async.rename, and record the stable-to-hashed mapping withrs.assets.register. - A template resolves the mapping with the
assetTera filter, such as{{ "/static/avatar-400.avif" | asset }}. Lua code resolves it withrs.assets.get_path. - The build order is the
before_buildhook, thenpages(), then rendering. A mapping registered inbefore_buildis thus visible topages()and to theassetfilter. - A source change that does not change the decoded pixels (such as a byte in the EXIF segment of a JPEG) leaves the variants byte-identical, so their hashes do not change.
Evidence#
2026-10-01, website repository, commit 9b63fc5: an agent read the rs-web source and reported the write_hashed and read-API limits. The build with rs.hash.file, rs.async.rename and rs.assets.register in before_build produced dist/static/avatar-400.9c2012864fa187c2.avif, and dist/index.html referenced only hashed names through the asset filter. A one-byte change inside the main image data changed the variant hashes; a byte in the EXIF segment changed only the hash of the full-size JPEG.