Class DataStreamAbstract

General purpose class used for encapsulating the reading and writing of data from and to various sources using a common interface.

Hierarchy (view full)

Constructors

  • Parameters

    • OptionalisInternalConstructor: boolean

    Returns DataStream

Accessors

  • get accessMode(): number
  • Gets the access mode of the stream.

    Returns number

  • get isFile(): boolean
  • Checks whether the stream reads/writes from a file system.

    Returns boolean

  • get isMemory(): boolean
  • Checks whether the stream reads/writes from memory.

    Returns boolean

  • get isReadable(): boolean
  • Determines if the stream is readable.

    Returns boolean

  • get isValid(): boolean
  • Checks whether the stream is valid.

    Returns boolean

  • get isWriteable(): boolean
  • Determines if the stream is writable.

    Returns boolean

  • get name(): string
  • Gets the name of the stream.

    Returns string

  • get size(): number
  • Returns the total size of the data to be read from the stream, or 0 if this is indeterminate for this stream.

    Returns number

Methods

  • Aligns the read/write cursor to a byte boundary. count determines the alignment in bytes. Note the requested alignment might not be achieved if count > 1 and it would move the cursor past the capacity of the buffer, as the cursor will be clamped to buffer end regardless of alignment.

    Parameters

    • Optionalcount: number

    Returns void

  • Creates a copy of this stream.

    Parameters

    • OptionalcopyData: boolean

      If true the internal stream data will be copied as well, otherwise it will just reference the data from the original stream (in which case the caller must ensure the original stream outlives the clone). This is not relevant for file streams.

    Returns DataStream

  • Close the stream. This makes further operations invalid.

    Returns void

  • Read count bytes from both streams and determines if both streams are byte-wise identical.

    The stream positions for both streams will be offset by count and must be manually reset.

    Parameters

    • readStream: DataStream
    • count: number

      Number of bytes to compare.

    Returns number

    True if identical.

    The stream must be created with READ access mode.

  • Returns true if the stream has reached the end.

    Returns boolean

  • Flushes any cached written data to the actual stream destination.

    Returns void

  • Returns a vector of bytes containing the entire stream.

    Parameters

    • OptionalseekToStart: boolean

      If true, will seek the stream to the start before reading.

    Returns number[]

    Byte data.

  • Returns a string containing the entire stream.

    Returns string

    String data encoded as UTF-8.

    This is a convenience method for text streams only, allowing you to retrieve a String object containing all the data in the stream. The stream will automatically seek to the beginning before reading the byte values as string.

  • Reads count bytes from the stream and returns them in an array. Advances the read pointer.

    Parameters

    • count: number

      Number of bytes to read.

    Returns number[]

    Array containing the read bytes.

    Stream must be created with READ access mode.

  • Reads a bool value from the stream

    Returns boolean

    The value

  • Reads a double value from the stream

    Returns number

    The value

  • Reads a float value from the stream

    Returns number

    The value

  • Reads an int16 value from the stream

    Returns number

    The value

  • Reads an int32 value from the stream

    Returns number

    The value

  • Reads an int64 value from the stream

    Returns number

    The value

  • Reads an int8 value from the stream

    Returns number

    The value

  • Read the requisite number of character from the stream as UTF-8 string. Advances the read pointer.

    Parameters

    • count: number

      Number of bytes to read.

    Returns string

    The resulting string.

    Stream must be created with READ access mode.

  • Reads a uint16 value from the stream

    Returns number

    The value

  • Reads a uint32 value from the stream

    Returns number

    The value

  • Reads a uint64 value from the stream

    Returns number

    The value

  • Reads a uint8 value from the stream

    Returns number

    The value

  • Repositions the read point to a specified byte.

    Parameters

    • pos: number

    Returns void

  • Skip a defined number of bytes. This can also be a negative value, in which case the file pointer rewinds a defined number of bytes.

    Parameters

    • count: number

    Returns void

  • Returns the current byte offset from beginning.

    Returns number

  • Writes the contents of the provided array into the stream at the current cursor location and advances the cursor.

    Parameters

    • data: number[]

      Array of data to write.

    Returns number

    Number of bytes actually written.

  • Writes a bool value to the stream

    Parameters

    • value: boolean

      The value

    Returns void

  • Writes a double value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Writes a float value to the string

    Parameters

    • value: number

      The value

    Returns void

  • Writes an int16 value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Writes an int32 value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Writes an int64 value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Writes an int8 value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Read count bytes from the stream and writes and advance both the readStream and this stream's cursor.

    Parameters

    • readStream: DataStream
    • count: number

      Number of bytes to write.

    Returns number

    Number of bytes actually written.

    The stream must be created with WRITE access mode.

  • Writes the provided narrow string to the steam. String is convered to the required encoding before being written.

    Parameters

    • string: string

      String containing narrow characters to write, encoded as UTF8.

    • Optionalencoding: EnumValue<StringEncoding, number>

      Encoding to convert the string to before writing.

    • OptionalisWritingBOM: boolean

    Returns void

  • Writes a uint16 value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Writes a uint32 value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Writes a uint64 value to the stream

    Parameters

    • value: number

      The value

    Returns void

  • Writes a uint8 value to the stream

    Parameters

    • value: number

      The value

    Returns void