W Wrapl, The Programming Language

Libraries IO.Stream

Modules

CloseMode

T : Std.Type.T

Close mode to pass to :close.

Read : CloseMode.T

Close the stream for further reading.

Write : CloseMode.T

Close the stream for further writing.

Both : CloseMode.T

Close the stream for further reading or writing.

Message

Error : Std.Type.T

Base type for error messages sent by stream methods.

ConvertError : Message.Error

Conversion error occurred.

GenericError : Message.Error

Generic error occurred.

ReadError : Message.Error

Read error occurred.

WriteError : Message.Error

Write error occurred.

FlushError : Message.Error

Flush error occurred.

SeekError : Message.Error

Seek error occurred.

CloseError : Message.Error

Close error occurred.

PollError : Message.Error

Poll error occurred.

SeekMode

T : Std.Type.T

Seek mode to pass to :seek.

Set : SeekMode.T

Seek to absolute relative to beginning of stream.

Cur : SeekMode.T

Seek to position relative to current position.

End : SeekMode.T

Seek to position relative to end of stream.

Types

T

A stream of bytes. Streams may be read-only, write-only or read-write and may support seeking. New stream types should inherit from one of the subtypes defined below.

ReaderT

Inherits from:
A readable stream. Subtypes of ReaderT should define at least the :read(@ReaderT, @Std.Address.T, @Std.Integer.SmallT) method, default implementations for the other read methods are provided in this module.

WriterT

Inherits from:
A writable stream. Subtypes of WriterT should define at least the :write(@WriterT, @Std.Address.T, @Std.Integer.SmallT) method, default implementations for the other write methods are provided in this module.

SeekerT

Inherits from:
A seekable stream. Subtypes of SeekerT should define at least the :seek(@SeekerT, @Std.Integer.SmallT) method, default implementations for the other seek methods are provided in this module.

TextReaderT

Inherits from:
A readable stream with added methods for reading text.

TextWriterT

Inherits from:
A writable stream with added methods for writing text.

Methods

:"@"(msg @ MessageT, _ = Std.String.T) : Std.String.T

:close(t @ T)

Closes t for further reading or writing

:closed(t @ T)

Fails if t is still open for reading or writing.

:copy(rd @ ReaderT, wr @ WriterT, count @ Std.Integer.SmallT) : Std.Integer.SmallT

Copies count bytes from rd to wr.

:copy(rd @ ReaderT, wr @ WriterT) : Std.Integer.T

Copies the contents of rd to wr.

:eoi(t @ ReaderT)

Succeeds if t has read an end of file marker.

:flush(t @ T)

Completes any pending operations on t.

Links rd and wr so that any input available on rd is written to wr.

The default implementation creates a new thread and so rd should block until input is available.

:read(rd @ TextReaderT) : Std.String.T

Reads the next line of text from rd and returns it as a string without the carriage return.

This methods differs from t:readx("\n", 0) in that it treats "\r\n" as a single carriage return.

:read(rd @ ReaderT, count @ Std.Integer.SmallT) : Std.String.T

Reads count bytes from rd and returns them as a string.

:read(rd @ ReaderT, buffer @ Std.Address.T, length @ Std.Integer.SmallT) : Std.Integer.SmallT

Reads up to length bytes from rd into buffer

Returns the number of bytes read

:readi(rd @ ReaderT, max @ Std.Integer.SmallT, terminal @ Std.String.T) : Std.String.T

Reads bytes from rd until either max bytes have been read, or a byte in terminal has been read, or rd is empty.

Returns the bytes read as a string including the final byte if it is in terminal.

Passing 0 for max will ignore the number of bytes read.

If terminal = "", then only the number of bytes is checked

If both max = 0 and terminal = "" then all the remaining bytes from rd are returned.

:readx(rd @ ReaderT, max @ Std.Integer.SmallT, terminal @ Std.String.T) : Std.String.T

Reads bytes from rd until either max bytes have been read, or a byte in terminal has been read, or rd is empty.

Returns the bytes read as a string excluding the final byte if it is in terminal.

Passing 0 for max will ignore the number of bytes read.

If terminal = "", then only the number of bytes is checked

If both max = 0 and terminal = "" then all the remaining bytes from rd are returned.

:rest(rd @ ReaderT) : Std.String.T

Returns the remaining contents of rd.

:seek(t @ SeekerT, position @ Std.Integer.SmallT, _ @ SeekMode.T)

Seeks to the positionth byte in t

:tell(t @ T) : Std.Integer.SmallT

Returns the current position in t

:write(wr @ WriterT, string @ Std.String.T) : WriterT

Writes string to wr.

:write(wr @ TextWriterT, value) : TextWriterT

Writes value@Std.String.T to wr.

:write(wr @ WriterT, buffer @ Std.Address.T, length @ Std.Integer.SmallT)

Writes up to length bytes to wr from buffer

Returns the number of bytes written

:writes(wr @ TextWriterT)

Writes each argument after the first to wr.