Import std.io.binary
BinaryReader
class
Public Class BinaryReader
Reads numbers, Bools, bytes, and text from another Reader. Each read throws an IOError of UNEXPECTED_END when the stream ends before what it reads, and ReadBytes and ReadText one of OTHER for a count past the 2147483647 bytes an array holds.
Examples
Local memory = MemoryStream()
Local writer = BinaryWriter(memory, ByteOrder.BIG)
Try writer.WriteUInt16(0x1234)
Try writer.WriteText("hi")
Expect(memory.ToArray() == [0x12, 0x34, 0x68, 0x69] As UInt8[])
Try memory.Seek(0, SeekOrigin.START)
Local reader = BinaryReader(memory, ByteOrder.BIG)
Expect((Try reader.ReadUInt16()) == 0x1234)
Expect((Try reader.ReadText(2)) == "hi")-
Reads
inner, its numbers' bytes inorder. -
Reads a UInt8.
-
Reads an Int8.
-
Reads a UInt16, in its ByteOrder.
-
Reads an Int16, in its ByteOrder.
-
Reads a UInt32, in its ByteOrder.
-
Reads an Int32, in its ByteOrder.
-
Reads a UInt64, in its ByteOrder.
-
Reads an Int64, in its ByteOrder.
-
Reads a Float32, its bits in its ByteOrder.
-
Reads a Float64, its bits in its ByteOrder.
-
A byte that's 0 for False, and anything else for True.
-
The next
countbytes, read a chunk at a time, so a count that the stream doesn't have, like a broken file's, ends in an IOError, not in asking for all that memory. Panics whencountis negative. -
The next
countbytes as text, with U+FFFD for each one that doesn't start well-formed UTF-8, read as ReadBytes reads them. Panics whencountis negative.
Report an issue with this page or with FutureBlitz on GitHub.