Skip to content

Latest commit

 

History

History
268 lines (155 loc) · 4.82 KB

ReadStream.md

File metadata and controls

268 lines (155 loc) · 4.82 KB

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

Name Type Default value Description
storage Uint8Array undefined The data to access.
readStartIndex number 0 The 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

Name Type Description
remaining number The 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

Name Type Description
readIndex number The current read index.

Returns

void


readFixedHex

readFixedHex(name, length, moveIndex?): string

Read fixed length as hex.

Parameters

Name Type Default value Description
name string undefined The name of the data we are trying to read.
length number undefined The length of the data to read.
moveIndex boolean true Move 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

Name Type Default value Description
name string undefined The name of the data we are trying to read.
length number undefined The length of the array to read.
moveIndex boolean true Move the index pointer on.

Returns

Uint8Array

The value.


readByte

readByte(name, moveIndex?): number

Read a byte from the stream.

Parameters

Name Type Default value Description
name string undefined The name of the data we are trying to read.
moveIndex boolean true Move the index pointer on.

Returns

number

The value.


readUInt16

readUInt16(name, moveIndex?): number

Read a UInt16 from the stream.

Parameters

Name Type Default value Description
name string undefined The name of the data we are trying to read.
moveIndex boolean true Move the index pointer on.

Returns

number

The value.


readUInt32

readUInt32(name, moveIndex?): number

Read a UInt32 from the stream.

Parameters

Name Type Default value Description
name string undefined The name of the data we are trying to read.
moveIndex boolean true Move the index pointer on.

Returns

number

The value.


readUInt64

readUInt64(name, moveIndex?): BigInteger

Read a UInt64 from the stream.

Parameters

Name Type Default value Description
name string undefined The name of the data we are trying to read.
moveIndex boolean true Move the index pointer on.

Returns

BigInteger

The value.


readBoolean

readBoolean(name, moveIndex?): boolean

Read a boolean from the stream.

Parameters

Name Type Default value Description
name string undefined The name of the data we are trying to read.
moveIndex boolean true Move the index pointer on.

Returns

boolean

The value.