Structured file parsing beyond the built-in read and write.
Import with use io. Provides structured file parsing beyond the built-in read[path] and write[path, content].
| Function | Description | Example |
|---|---|---|
csv[path] | Parse CSV — a file, a URL or an S3 object — into array of maps (error-value on failure) | Structured files: use io · The standard library's layer: use sys |
lines[path] | Read a file, a URL or an S3 object as array of lines (error-value on failure); a file is read a block at a time (sys.file_lines), so its whole text is not held beside its lines | Structured files: use io · The standard library's layer: use sys |
Note: Basic file I/O (read[path], write[path, content]) are builtins available without any import. The io module adds structured parsing only.
use io
write['/tmp/data.csv', 'name,age\nalice,30\nbob,25\n']
rows = csv['/tmp/data.csv']
log[len[rows]] --- 2
log[rows[0].name] --- alice
log[rows[0].age] --- 30
ls = lines['/tmp/data.txt']
log[len[ls]] --- number of lines
log[ls[0]] --- first line
--- error handling
bad = csv['/tmp/missing.csv']
log[bad.ok] --- false
log[bad.reason] --- error message
Generated by crow test --docs --write from the language specification, section 11 and 13. Edit the spec, not this page.