File.ByteReader

read

defn

(Fn [(Ref File a), Int] (Result (Array Byte) String))

                        (read file n)
                    

Reads an array of exactly n bytes from a file. This is a convenient wrapper that fixes the returntype of File.read to (Array Byte)

read-at-most

defn

(Fn [(Ref File a), Int] (Result (Array Byte) String))

                        (read-at-most f n)
                    

Reads up to n bytes from a file, stopping early at the end of it. Returns a result containing however many bytes were there, which may be fewer than n and may be none at all. Only a negative n is an error.

Use this to read a file in chunks, where a short final chunk is expected; use read-bytes when anything less than n bytes means the read failed.

read-byte

defn

(Fn [(Ptr FILE)] (Result Byte String))

                        (read-byte file)
                    

Read a single byte from a file.

read-bytes

defn

(Fn [(Ref File a), Int] (Result (Array Byte) String))

                        (read-bytes f n)
                    

Read exactly n bytes from a file. Returns a result containing the bytes on success, and an error if n is negative or if the file held fewer than n bytes, in which case the bytes that were read are discarded.

See read-at-most for a read that tolerates a short file.