Import std.io.memory
std.io.memory
Streams over bytes and Strings in memory.
Streams over memory: MemoryStream, bytes to read, write, and move around in, as a file's are; StringReader, which reads a String's UTF-8; and StringWriter, which collects text.
std/io/memory.fb
Types
MemoryStream
class
Public Class MemoryStream Implements Reader, Writer, Seeker
Bytes in memory that it reads, writes, and moves around in, as a file's are, from where it is, which they grow past as they're written. Writing past the end fills what's between with 0s.
Examples
Local memory = MemoryStream()
Try memory.WriteText("hello")
Expect(memory.Count == 5)
Try memory.Seek(1, SeekOrigin.START)
Expect((Try ReadAllText(memory)) == "ello")-
One of a copy of the
bytes, from their start, or an empty one. -
How many bytes it has.
-
Reads up to into.Count bytes from where it is into
into, moves on past them, and gives how many, or 0 at its end. -
Writes from's bytes where it is, over what's there and past its end, and moves on past them. Throws an IOError when it would hold more than 2147483647 bytes.
-
Moves to
offsetbytes fromorigin, which can be past its end, where a Write fills what's between with zeros, and gives where it is now. Throws an IOError before its start. -
Its bytes, in a new array.
StringReader
class
Public Class StringReader Implements Reader, Seeker
Reads a String's UTF-8 bytes, and moves around in them.
Examples
Local reader = StringReader("héllo")
Expect(reader.Count == 6)
Expect((Try ReadAllText(reader)) == "héllo")-
A StringReader of
text's UTF-8 bytes. -
How many bytes the text has.
-
Reads up to into.Count of the text's bytes from where it is into
into, moves on past them, and gives how many, or 0 at its end. -
Moves to
offsetbytes fromorigin, and gives where it is now. Throws an IOError before its start.
StringWriter
class
Public Class StringWriter Implements Writer
Collects what's written to it, as text, which ToString gives.
Examples
Local writer = StringWriter()
Try Copy(StringReader("copied"), writer)
Try writer.WriteText(" and added")
Expect(writer.ToString() == "copied and added")-
A new StringWriter, with nothing written.
-
How many bytes it has.
-
Adds from's bytes to what it has. Throws an IOError when it would hold more than 2147483647 bytes.
-
What it has, as text, with U+FFFD for each byte that doesn't start well-formed UTF-8.
Report an issue with this page or with FutureBlitz on GitHub.