Skip to content
FutureBlitz

    Install

    Import std.io.binary

    BinaryReader

    std.io.binary

    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")

    std/io/binary.fb, line 37

    • Public New(inner: Reader, order: ByteOrder = ByteOrder.LITTLE) constructor #

      Reads inner, its numbers' bytes in order.

    • Public Method ReadUInt8(): UInt8 Throws IOError method #

      Reads a UInt8.

    • Public Method ReadInt8(): Int8 Throws IOError method #

      Reads an Int8.

    • Public Method ReadUInt16(): UInt16 Throws IOError method #

      Reads a UInt16, in its ByteOrder.

    • Public Method ReadInt16(): Int16 Throws IOError method #

      Reads an Int16, in its ByteOrder.

    • Public Method ReadUInt32(): UInt32 Throws IOError method #

      Reads a UInt32, in its ByteOrder.

    • Public Method ReadInt32(): Int32 Throws IOError method #

      Reads an Int32, in its ByteOrder.

    • Public Method ReadUInt64(): UInt64 Throws IOError method #

      Reads a UInt64, in its ByteOrder.

    • Public Method ReadInt64(): Int64 Throws IOError method #

      Reads an Int64, in its ByteOrder.

    • Public Method ReadFloat32(): Float32 Throws IOError method #

      Reads a Float32, its bits in its ByteOrder.

    • Public Method ReadFloat64(): Float64 Throws IOError method #

      Reads a Float64, its bits in its ByteOrder.

    • Public Method ReadBool(): Bool Throws IOError method #

      A byte that's 0 for False, and anything else for True.

    • @PanicsAtCaller Public Method ReadBytes(count: Int64): UInt8[] Throws IOError method #

      The next count bytes, 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 when count is negative.

    • @PanicsAtCaller Public Method ReadText(count: Int64): String Throws IOError method #

      The next count bytes as text, with U+FFFD for each one that doesn't start well-formed UTF-8, read as ReadBytes reads them. Panics when count is negative.

    Report an issue with this page or with FutureBlitz on GitHub.