Ingest Files

To import files as a Str or a List U8 (list of bytes):

import "some-file.txt" as some_str : Str
import "some-file" as some_bytes : List U8

This prevents needing to set up the error handling for the file reading.

The file content is included in the Roc app executable, if you publish the executable, you do not need to provide the file alongside it.

Full Code

app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.20.0/X73hGh05nNTkDHU06FHC0YfFaQB1pimX7gncRcao5mU.tar.br" }

import cli.Stdout
import cli.Arg exposing [Arg]
import "sample.txt" as sample : Str

main! : List Arg => Result {} _
main! = |_args|
    Stdout.line!("Contents of sample.txt: ${sample}")

Output

Run this from the directory that has main.roc in it:

$ roc main.roc
Contents of sample.txt: The quick brown fox jumps over the lazy dog