-
Notifications
You must be signed in to change notification settings - Fork 0
module std.io
Jan Špaček edited this page Apr 14, 2016
·
1 revision
This module provides a basic IO library for reading and writing bytes from files and the standard IO streams.
-
IO streams are handles to opened files
-
(io? io)
returns true ifio
is an IO stream. -
(io-eof? io)
returns true if the streamio
reached end of file. -
(io-error? io)
returns true if there was an error reading from or writing toio
.
-
-
Standard IO streams
-
(io-stdin)
returns the standard input stream. -
(io-stdout)
returns the standard output stream. -
(io-stderr)
returns the standard error stream.
-
-
Files
-
(io-file-read path)
reads the whole contents of file atpath
or false if an error occurs. -
(io-file-open path)
opens file atpath
for reading. -
(io-file-create path)
opens file atpath
for writing and truncates the file or creates a new one. -
(io-file-append path)
opens file atpath
for appending or creates a new one.
-
-
Reading from streams
-
(io-read-byte io)
reads a byte from streamio
or returns false if the read was not successful (for example, end of file was reached). -
(io-read-str io len)
reads at mostlen
bytes from streamio
. If an error occurs (including end of file), less thanlen
bytes may be returned. -
(io-read-all-str io)
reads all remaining bytes from streamio
into a string. -
(io-read-line io)
reads a line terminated by\n
(including the terminator if it is present). -
(io-read-word io)
reads a word separated by whitespace from streamio
. The whitespace preceding the word is lost, but the whitespace following the word is left in the stream. -
(io-read-int io)
reads an integer from streamio
. The integer can be preceded by whitespace and can have a sign, either+
or-
. Only decimal digits0
to9
are allowed, the integer ends at the first non-digit. However, the whitespace following the last digit is also consumed. If an integer could not be read, the function returns false. -
(io-read-number io)
reads a float with optional sign and exponent (denoted bye
orE
). Both the integer and the fractional parts are optional (so a single.
is assumed to be0
). The whitespace following the number is consumed from the stream. If an error occurs, this function returns false.
-
-
Writing to streams
-
(io-write-byte io byte)
writesbyte
into the streamio
. -
(io-write io x)
writes into the streamio
the stringified valuex
. -
(io-write-line io x)
writes into the streamio
the stringified valuex
followed by a newline.
-