Class: MemoryStream

MemoryStream(bytes)

Memory Stream for seeking, reading, and writing to a memory buffer (modeled after C# MemoryStream). If the memory buffer is not specified then an internal resizable buffer will be created.

Constructor

new MemoryStream(bytes)

Create a memory stream.
Parameters:
Name Type Default Description
bytes Uint8Array null Optional existing byte array to use as backing buffer. If omitted a new backing array will be created automatically.
Source:

Classes

MemoryStream

Methods

(async) canRead() → {Promise.<boolean>}

Source:
Returns:
If the stream can be used for reading.
Type
Promise.<boolean>

(async) canSeek() → {Promise.<boolean>}

Source:
Returns:
If the stream is seekable.
Type
Promise.<boolean>

(async) canWrite() → {Promise.<boolean>}

Source:
Returns:
If the stream can be used for writing.
Type
Promise.<boolean>

(async) close()

Close any resources the stream is using. Not-Applicable for memory stream.
Source:

(async) flush()

Flush the stream. Not-Applicable for memory stream.
Source:

(async) getPosition() → {Promise.<number>}

Source:
Returns:
The position of the stream.
Type
Promise.<number>

(async) length() → {Promise.<number>}

Source:
Returns:
The length of the stream.
Type
Promise.<number>

(async) read(buffer, offset, count) → {Promise.<number>}

Read a sequence of bytes into the provided buffer.
Parameters:
Name Type Description
buffer Uint8Array The buffer to write the bytes that are read from the stream.
offset number The offset of the buffer that will be used to write the bytes.
count number The length of the bytes that can be read from the stream and written to the buffer.
Source:
Throws:
IOException Thrown if there is an IO error.
Returns:
The number of bytes read.
Type
Promise.<number>

(async) seek(offset, origin) → {Promise.<number>}

Seek to a position in the stream.
Parameters:
Name Type Description
offset number The offset to use.
origin SeekOrigin.Begin The origin type.
Source:
Returns:
The position after the seeking was complete.
Type
Promise.<number>

(async) setLength(value)

Changes the length of the stream. The capacity of the stream might also change if the value is lesser than the current capacity.
Parameters:
Name Type Description
value Promise.<number> The new position of the stream.
Source:

(async) setPosition(value)

Changes the current position of the stream. For more options use seek() method.
Parameters:
Name Type Description
value The new position of the stream.
Source:

toArray() → {Uint8Array}

Convert the stream to an array:
Source:
Returns:
A byte array containing the data from the stream.
Type
Uint8Array

(async) write(buffer, offset, count)

Write a sequence of bytes into the stream.
Parameters:
Name Type Description
buffer Uint8Array The buffer that the bytes will be read from.
offset number The position offset that will be used to read from the buffer.
count number The number of bytes that will be written to the stream.
Source: