diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-04-07 11:30:27 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-04-07 11:30:27 +0200 |
commit | 5ee68d500d71c0dd2aa0dde5c75381969833249a (patch) | |
tree | 0b14791fcf8d8c83daf3e6ee16200e5a919e7686 /lib.c | |
parent | df6b86173c4979aea636907b8f3fb4d0c855ea94 (diff) |
fs: implement `fs.readfile()` and `fs.writefile()`
The `fs.readfile()` and `fs.writefile()` functions allow efficient reading
and writing of whole files, reducing the required boilerplace code compared
to using the `open()`/`read()`/`write()`/`close()` API.
- `fs.readfile()` takes two arguments; the path to open and an optional
limit value. If limit is omitted, `null` or negative, the entire file
contents are read, otherwise the specified amount of bytes. Returns the
read file contents as string or `null` on error.
- `fs.writefile()` takes three arguments; the path to open/create, the
contents to write and an optional limit value. If limit is omitted, the
entire content is written, otherwise just the specified amount of bytes.
Non-string content arguments are internally converted to strings, `null`
is treated as empty string. Returns the amount of bytes written or `null`
on error.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
0 files changed, 0 insertions, 0 deletions