@head @module memorystream @title memorystream: Memory-based streams

This module defines the MemoryStream class that allows creating memory-based streams. @see The @ref{Stream} class is defined in the @ref{io} module. @end

Class MemoryStream

@inherits Stream @supertypes @class MemoryStream([contents as Str]) @desc Construct a MemoryStream instance. If the contents argument is provided, the stream initially contains this string argument. Otherwise, the stream is initially empty. The stream pointer will always be initially at the start of the stream. MemoryStream instances are always buffered and support both reading and writing. @end

MemoryStream methods

MemoryStream supports all the @ref{Stream} methods and the following additional methods: @fun seek(n as Int) @desc Move the stream pointer to the specified index. 0 refers to the start of the stream, 1 to the position between the first and the second character, and so on. @end @fun pos() as Int @desc Return the current stream pointer index. @end @fun size() as Int @desc Return the length of the stream contents. @end @fun contents() as Str @desc Return the contents of the stream as a string. This method works also if the stream is closed. @end

Example

@example import memorystream def Main() var s = MemoryStream("Line 1" + Newline + "Line 2") s.readLn() -- Result: "Line 1" s.readLn() -- Result: "Line 2" end @end