Builtin

os.file_content

os.file_content{ path:str, sep:str, format:str, offset:int, size:int, r:{seq:int, ss:str}, err:str }

Reads the file contents for the file paths provided.

Defaults to an r tuple per line (sep default is "\n"). Or format:="b" can be used to read in one piece (r then has a single tuple with ss=hex).

Defaults to reading from offset:=0 bytes into the file.

Defaults to reading whole file, or else size lines (or size bytes).

Check err for any failures.

Examples

init.ra
import("os")
os.file_content(path:="init.ra")

┌─────┬────────┬────────┬──────┬───────────────────────────────────────────────┬─────┐
│ sep │ format │ offset │ size │ r                                             │ err │
├─────┼────────┼────────┼──────┼───────────────────────────────────────────────┼─────┤
│ \n  │        │      0 │    1 │ ┌─────┬─────────────────────────────────────┐ │     │
│     │        │        │      │ │ seq │ ss                                  │ │     │
│     │        │        │      │ ├─────┼─────────────────────────────────────┤ │     │
│     │        │        │      │ │   0 │ print("schema_one init.ra loading") │ │     │
│     │        │        │      │ └─────┴─────────────────────────────────────┘ │     │
└─────┴────────┴────────┴──────┴───────────────────────────────────────────────┴─────┘


bulk file read
import("os")
os.file_content & {path:str}{
    ["init.ra"], 
    ["testwrite1"]
}

┌────────────┬─────┬────────┬────────┬──────┬───────────────────────────────────────────────┬─────┐
│ path       │ sep │ format │ offset │ size │ r                                             │ err │
├────────────┼─────┼────────┼────────┼──────┼───────────────────────────────────────────────┼─────┤
│ init.ra    │ \n  │        │      0 │    1 │ ┌─────┬─────────────────────────────────────┐ │     │
│            │     │        │        │      │ │ seq │ ss                                  │ │     │
│            │     │        │        │      │ ├─────┼─────────────────────────────────────┤ │     │
│            │     │        │        │      │ │   0 │ print("schema_one init.ra loading") │ │     │
│            │     │        │        │      │ └─────┴─────────────────────────────────────┘ │     │
│ testwrite1 │ \n  │        │      0 │    2 │ ┌─────┬────────────────┐                      │     │
│            │     │        │        │      │ │ seq │ ss             │                      │     │
│            │     │        │        │      │ ├─────┼────────────────┤                      │     │
│            │     │        │        │      │ │   0 │ this is a file │                      │     │
│            │     │        │        │      │ │   1 │ with two lines │                      │     │
│            │     │        │        │      │ └─────┴────────────────┘                      │     │
└────────────┴─────┴────────┴────────┴──────┴───────────────────────────────────────────────┴─────┘