Skip to content

Read a file to bytes

The fs.read function is used to read a file and return a std.io.Bytes. The first argument is the file path.

To read the std.io.Bytes to a UTF-8 string, you can use the to_string method.

WARNING

The valid UTF-8 bytes will be converted to string, and invalid UTF-8 bytes, it will be replaced with U+FFFD, e.g. �

Or use encode_to_string method to convert to a string with a specific encoding.

nv,no_run