memorystream: Memory-based streams

This module defines the MemoryStream class that allows creating memory-based streams.

See also: The Stream class is defined in the io module.

The MemoryStream class

class MemoryStream([contents])
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. MemoryStream inherits from io::Stream.

MemoryStream methods

MemoryStream supports all the Stream methods and the following additional methods:

seek(n)
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.
pos()
Return the current stream pointer index.
size()
Return the length of the stream contents.
contents()
Return the contents of the stream as a string. This method works also if the stream is closed.

Example

import memorystream

sub Main()
  var s = MemoryStream("Line 1" + Newline + "Line 2")
  s.readLn() -- Result: "Line 1"
  s.readLn() -- Result: "Line 2"
end