Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BinaryReader

Reads primitive data types as binary values in a specific encoding.

Hierarchy

  • BinaryReader

Index

Constructors

constructor

  • Initializes a new instance of the BinaryReader class based on the specified IFile instance and character encoding, and optionally leaves the file open.

    Parameters

    • input: IFile

      The input IFile instance.

    • Default value encoding: BufferEncoding | string | IEncoding = "utf8"

      The character encoding to use, or an object implementing the IEncoding interface. Default to 'utf8'

    • Default value leaveOpen: boolean = false

      true to leave the file open after the BinaryReader object is disposed; otherwise, false. Default to false.

    Returns BinaryReader

Properties

Private Readonly _2BytesPerChar

_2BytesPerChar: boolean = false

Private Readonly _decoder

_decoder: IDecoder

Private _disposed

_disposed: boolean = false

Private Readonly _file

_file: IFile

Private Readonly _leaveOpen

_leaveOpen: boolean = false

Private _nReadBytes

_nReadBytes: number = 0

Accessors

file

Methods

close

  • close(): void

Private internalRead

  • internalRead(numBytes: number): Buffer

Private internalReadByte

  • internalReadByte(): number

Private internalReadChars

  • internalReadChars(buffer: SubArray<char>): number

Private internalReadString

  • internalReadString(stringLength: number): string

peekChar

  • peekChar(): number
  • Returns the next available character and does not advance the byte or character position.

    Returns number

    The next available character, or -1 if no more characters are available or the file does not support seeking.

read7BitEncodedInt

  • read7BitEncodedInt(): number
  • Reads in a 32-bit integer in compressed format.

    Returns number

    A 32-bit integer in compressed format.

read7BitEncodedInt64

  • read7BitEncodedInt64(): bigint
  • Reads in a 64-bit integer in compressed format.

    Returns bigint

    A 64-bit integer in compressed format.

readBoolean

  • readBoolean(): boolean
  • Reads a boolean value from the current file and advances the current position of the file by one byte.

    Returns boolean

    true if the byte is nonzero; otherwise, false.

readByte

  • readByte(): number
  • Reads the next byte from the current file and advances the current position of the file by one byte.

    Returns number

    The next byte read from the current file.

readBytes

  • readBytes(count: number): Buffer
  • Reads the specified number of bytes from the current file into a buffer and advances the current position by that number of bytes.

    Parameters

    • count: number

      The number of bytes to read. This value must be 0 or a non-negative number or an exception will occur.

    Returns Buffer

    A buffer containing data read from the underlying file. This might be less than the number of bytes requested if the end of the file is reached.

readChar

  • Reads the next character from the current file and advances the current position of the file in accordance with the Encoding used and the specific character being read from the file.

    Returns char

    A character read from the current file.

readCharCode

  • readCharCode(): number
  • Reads characters from the underlying file and advances the current position of the file in accordance with the Encoding used and the specific character being read from the file.

    Returns number

    The next character from the input file, or -1 if no characters are currently available.

readChars

  • readChars(count: number): char[]
  • Reads the specified number of characters from the current file, returns the data in a character array, and advances the current position in accordance with the Encoding used and the specific character being read from the file.

    Parameters

    • count: number

      The number of characters to read.

    Returns char[]

    A character array containing data read from the underlying file. This might be less than the number of characters requested if the end of the file is reached.

readDouble

  • readDouble(): number
  • Reads an 8-byte floating point value from the current file and advances the current position of the file by eight bytes.

    Returns number

    An 8-byte floating point value read from the current file.

readInt16

  • readInt16(): number
  • Reads a 2-byte signed integer from the current file and advances the current position of the file by two bytes.

    Returns number

    A 2-byte signed integer read from the current file.

readInt32

  • readInt32(): number
  • Reads a 4-byte signed integer from the current file and advances the current position of the file by four bytes.

    Returns number

    A 4-byte signed integer read from the current file.

readInt64

  • readInt64(): bigint
  • Reads an 8-byte signed integer from the current file and advances the current position of the file by eight bytes.

    Returns bigint

    An 8-byte signed integer read from the current file.

readIntoBuffer

  • readIntoBuffer(buffer: Buffer): number
  • Reads a sequence of bytes from the current file and advances the position within the file by the number of bytes read.

    Parameters

    • buffer: Buffer

      A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.

    Returns number

    The total number of bytes read into the buffer. This can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or zero (0) if the end of the file has been reached.

readIntoBufferEx

  • readIntoBufferEx(buffer: Buffer, index: number, count: number): number
  • Reads the specified number of bytes from the file, starting from a specified point in the buffer.

    Parameters

    • buffer: Buffer

      The buffer to read data into.

    • index: number

      The starting point in the buffer at which to begin reading into the buffer.

    • count: number

      The number of bytes to read.

    Returns number

    The number of bytes read into buffer. This might be less than the number of bytes requested if that many bytes are not available, or it might be zero if the end of the file is reached.

readIntoChars

  • readIntoChars(buffer: char[]): number
  • Reads, from the current file, the same number of characters as the length of the provided buffer, writes them in the provided buffer, and advances the current position in accordance with the Encoding used and the specific character being read from the file.

    Parameters

    • buffer: char[]

      A view of characters. When this method returns, the contents of this region are replaced by the characters read from the current source.

    Returns number

    The total number of characters read into the buffer. This might be less than the number of characters requested if that many characters are not currently available, or it might be zero if the end of the file is reached.

readIntoCharsEx

  • readIntoCharsEx(buffer: char[], index: number, count: number): number
  • Reads the specified number of characters from the file, starting from a specified point in the character array.

    Parameters

    • buffer: char[]

      The buffer to read data into.

    • index: number

      The starting point in the buffer at which to begin reading into the buffer.

    • count: number

      The number of characters to read.

    Returns number

    The total number of characters read into the buffer. This might be less than the number of characters requested if that many characters are not currently available, or it might be zero if the end of the file is reached.

readRawString

  • readRawString(length: number): string
  • Reads a string from the current file. You have to provide the length of it.

    Parameters

    • length: number

      The number of bytes to read.

    Returns string

    The string being read.

readSByte

  • readSByte(): number
  • Reads a signed byte from this file and advances the current position of the file by one byte.

    Returns number

    A signed byte read from the current file.

readSingle

  • readSingle(): number
  • Reads a 4-byte floating point value from the current file and advances the current position of the file by four bytes.

    Returns number

    A 4-byte floating point value read from the current file.

readString

  • readString(): string
  • Reads a string from the current file. The string is prefixed with the length, encoded as an integer seven bits at a time.

    Returns string

    The string being read.

readUInt16

  • readUInt16(): number
  • Reads a 2-byte unsigned integer from the current file using little-endian encoding and advances the position of the file by two bytes.

    Returns number

    A 2-byte unsigned integer read from this file.

readUInt32

  • readUInt32(): number
  • Reads a 4-byte unsigned integer from the current file and advances the position of the file by four bytes.

    Returns number

    A 4-byte unsigned integer read from this file.

readUInt64

  • readUInt64(): bigint
  • Reads an 8-byte unsigned integer from the current file and advances the position of the file by eight bytes.

    Returns bigint

    An 8-byte unsigned integer read from this file.

Private throwIfDisposed

  • throwIfDisposed(): void

Generated using TypeDoc