| 1 | module obj |
| 2 | |
| 3 | import os |
| 4 | import os.asset |
| 5 | |
| 6 | // read a file as single lines |
| 7 | pub fn read_lines_from_file(file_path string) []string { |
| 8 | if os.exists(file_path) { |
| 9 | return os.read_lines(file_path) or { [] } |
| 10 | } |
| 11 | return read_bytes_from_file(file_path).bytestr().split_into_lines() |
| 12 | } |
| 13 | |
| 14 | // read a file as []u8 |
| 15 | pub fn read_bytes_from_file(file_path string) []u8 { |
| 16 | if os.exists(file_path) { |
| 17 | return os.read_bytes(file_path) or { [] } |
| 18 | } |
| 19 | mpath := 'models/${file_path}' |
| 20 | return asset.read_bytes('assets', mpath) or { |
| 21 | eprintln('Model file NOT FOUND: `${mpath}`') |
| 22 | exit(0) |
| 23 | } |
| 24 | } |
| 25 | |