Skip to content
FutureBlitz

    Install

    Import std.io.binary

    std.io.binary

    Binary streams: BinaryReader reads numbers, Bools, bytes, and text from a Reader, and BinaryWriter writes them to a Writer, each number's bytes in the order its ByteOrder says, whatever the machine's own order is.

    std/io/binary.fb

    Types

    ByteOrder enum

    Public Enum ByteOrder

    The order of a number's bytes.

    std/io/binary.fb, line 11

    • LITTLE enum member #

      Its lowest byte first, as x86-64's and AArch64's memory has them.

    • BIG enum member #

      Its highest byte first, as network protocols do.

    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.

    std/io/binary.fb, line 21

    • 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.

    BinaryWriter class

    Public Class BinaryWriter

    Writes numbers, Bools, bytes, and text to another Writer.

    std/io/binary.fb, line 112

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

      Writes inner, its numbers' bytes in order.

    • Public Method WriteUInt8(value: UInt8) Throws IOError method #

      Writes value, a byte.

    • Public Method WriteInt8(value: Int8) Throws IOError method #

      Writes value, a byte.

    • Public Method WriteUInt16(value: UInt16) Throws IOError method #

      Writes value, in its ByteOrder.

    • Public Method WriteInt16(value: Int16) Throws IOError method #

      Writes value, in its ByteOrder.

    • Public Method WriteUInt32(value: UInt32) Throws IOError method #

      Writes value, in its ByteOrder.

    • Public Method WriteInt32(value: Int32) Throws IOError method #

      Writes value, in its ByteOrder.

    • Public Method WriteUInt64(value: UInt64) Throws IOError method #

      Writes value, in its ByteOrder.

    • Public Method WriteInt64(value: Int64) Throws IOError method #

      Writes value, in its ByteOrder.

    • Public Method WriteFloat32(value: Float32) Throws IOError method #

      Writes value, its bits in its ByteOrder.

    • Public Method WriteFloat64(value: Float64) Throws IOError method #

      Writes value, its bits in its ByteOrder.

    • Public Method WriteBool(value: Bool) Throws IOError method #

      A byte: 1 for True, and 0 for False.

    • Public Method WriteBytes(bytes: UInt8[]) Throws IOError method #

      Writes bytes as they are.

    • Public Method WriteText(text: String) Throws IOError method #

      The text's UTF-8 bytes, without anything to say how many there are.

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