std/resource
Files a program needs, named by a string literal where the signature says what kind of file it is
(docs/design/RESOURCES.md): a Resource ships beside the program and is read while it runs, an EmbeddedBytes and
an EmbeddedText are in the binary. A literal where one of them is expected is resolved by the compiler against the
file that writes it, and a file that is not there is an error at that line; a String value never becomes one.
fn load(sheet: Resource): String {
sheet.name()
}
print load("./hero.png")
torb build ships the files of the Resource literals beside the binary, and bytes() and text() read them from
there, failing with a ResourceError. This is slices 1 to 3 of the design: the types, the literal and the stable
name, embedding, and shipping.
Modules
std/resource/error[ResourceError]: why reading a shippedResourcefailed (docs/design/RESOURCES.md section 4).std/resource/resource[Resource], [EmbeddedBytes] and [EmbeddedText]: the three types a string literal names a file of the package with (docs/design/RESOURCES.md section 4).
Everything
- type
EmbeddedBytesA file whose bytes are in the binary. - type
EmbeddedTextA file whose text is in the binary, so reading it cannot fail: the compiler reads the file, and checks its UTF-8, where the literal names it (slice 2 of docs/design/RESOURCES.md). - type
ResourceA file that ships with the program and is read while it runs, found relative to the program and never to the working directory. - type
ResourceErrorWhy reading aResourcefailed: it is not beside the program, it cannot be read, it is not text, or the program cannot tell where it is.