new Reader()
A wrapper class over the native ReadableStreamDefaultReader. This additionally implements pushing back data on the stream, which lets us implement peeking and a host of convenience functions. It also lets you read data other than streams, such as a Uint8Array.
Methods
cancel()
Cancel the stream.
(async) peekBytes() → {Promise.<(Uint8Array|String|Undefined)>}
Peek (look ahead) a specific amount of bytes/characters, unless the stream ends before that amount.
Returns:
- Type
- Promise.<(Uint8Array|String|Undefined)>
(async) read() → {Promise.<Object>}
Read a chunk of data.
Returns:
Either { done: false, value: Uint8Array | String } or { done: true, value: undefined }
- Type
- Promise.<Object>
(async) readByte() → {Promise.<(Number|String|Undefined)>}
Read a single byte/character.
Returns:
- Type
- Promise.<(Number|String|Undefined)>
(async) readBytes() → {Promise.<(Uint8Array|String|Undefined)>}
Read a specific amount of bytes/characters, unless the stream ends before that amount.
Returns:
- Type
- Promise.<(Uint8Array|String|Undefined)>
(async) readLine() → {Promise.<(String|Undefined)>}
Read up to and including the first \n character.
Returns:
- Type
- Promise.<(String|Undefined)>
(async) readToEnd(join) → {Promise.<(Uint8array|String|Any)>}
Read the stream to the end and return its contents, concatenated by the join function (defaults to streams.concat).
Parameters:
Name | Type | Description |
---|---|---|
join |
function |
Returns:
the return value of join()
- Type
- Promise.<(Uint8array|String|Any)>
releaseLock()
Allow others to read the stream.
unshift(…values)
Push data to the front of the stream. Data must have been read in the last call to read*.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
values |
Uint8Array | String | Undefined |
<repeatable> |