Skip to main content

Class: ReadStream

Keep track of the read index within a stream.

Table of contents

Constructors

Methods

Constructors

constructor

new ReadStream(storage, readStartIndex?)

Create a new instance of ReadStream.

Parameters

NameTypeDefault valueDescription
storageUint8ArrayundefinedThe data to access.
readStartIndexnumber0The index to start the reading from.

Methods

length

length(): number

Get the length of the storage.

Returns

number

The storage length.


hasRemaining

hasRemaining(remaining): boolean

Does the storage have enough data remaining.

Parameters

NameTypeDescription
remainingnumberThe amount of space needed.

Returns

boolean

True if it has enough data.


unused

unused(): number

How much unused data is there.

Returns

number

The amount of unused data.


getReadIndex

getReadIndex(): number

Get the current read index.

Returns

number

The current read index.


setReadIndex

setReadIndex(readIndex): void

Set the current read index.

Parameters

NameTypeDescription
readIndexnumberThe current read index.

Returns

void


readFixedHex

readFixedHex(name, length, moveIndex?): string

Read fixed length as hex.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
lengthnumberundefinedThe length of the data to read.
moveIndexbooleantrueMove the index pointer on.

Returns

string

The hex formatted data.


readBytes

readBytes(name, length, moveIndex?): Uint8Array

Read an array of byte from the stream.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
lengthnumberundefinedThe length of the array to read.
moveIndexbooleantrueMove the index pointer on.

Returns

Uint8Array

The value.


readUInt8

readUInt8(name, moveIndex?): number

Read a byte from the stream.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
moveIndexbooleantrueMove the index pointer on.

Returns

number

The value.


readUInt16

readUInt16(name, moveIndex?): number

Read a UInt16 from the stream.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
moveIndexbooleantrueMove the index pointer on.

Returns

number

The value.


readUInt32

readUInt32(name, moveIndex?): number

Read a UInt32 from the stream.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
moveIndexbooleantrueMove the index pointer on.

Returns

number

The value.


readUInt64

readUInt64(name, moveIndex?): BigInteger

Read a UInt64 from the stream.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
moveIndexbooleantrueMove the index pointer on.

Returns

BigInteger

The value.


readUInt256

readUInt256(name, moveIndex?): BigInteger

Read a UInt256 from the stream.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
moveIndexbooleantrueMove the index pointer on.

Returns

BigInteger

The value.


readBoolean

readBoolean(name, moveIndex?): boolean

Read a boolean from the stream.

Parameters

NameTypeDefault valueDescription
namestringundefinedThe name of the data we are trying to read.
moveIndexbooleantrueMove the index pointer on.

Returns

boolean

The value.