Constructor
new Decoder(optionsopt)
Create a parsing stream.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
options |
DecoderOptions
|
<optional> |
{} | Options. |
Extends
Methods
(static) decodeAll(input, optionsopt, cbopt) → {Promise.<(Array.<ExtendedResults>|Array.<any>)>}
Decode all of the CBOR items in the input. This will error if there are
more bytes left over at the end.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input |
BufferLike
|
What to parse? | ||
options |
DecoderOptions
|
decodeAllCallback
|
string
|
<optional> |
{} | Decoding options, the callback, or the input encoding. |
cb |
decodeAllCallback
|
<optional> |
null | Callback. |
Throws:
-
No input specified.
- Type
-
TypeError
(static) decodeAllSync(input, optionsopt) → {Array.<ExtendedResults>|Array.<any>}
Decode all of the CBOR items in the input into an array. This will throw
an exception if the input is not valid CBOR; a zero-length input will
return an empty array.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input |
BufferLike
|
What to parse? | ||
options |
DecoderOptions
|
string
|
<optional> |
{} | Options or encoding for input. |
Throws:
-
-
No input provided.
- Type
-
TypeError
-
-
-
Insufficient data provided.
- Type
-
Error
-
(static) decodeFirst(input, optionsopt, cbopt) → {Promise.<(ExtendedResults|any)>}
Decode the first CBOR item in the input. This will error if there are
more bytes left over at the end (if options.extendedResults is not true),
and optionally if there were no valid CBOR bytes in the input. Emits the
{Decoder.NOT_FOUND} Symbol in the callback if no data was found and the
`required` option is false.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input |
BufferLike
|
What to parse? | ||
options |
DecoderOptions
|
decodeCallback
|
string
|
<optional> |
{} | Options, the callback, or input encoding. |
cb |
decodeCallback
|
<optional> |
null | Callback. |
Throws:
-
No input provided.
- Type
-
TypeError
(static) decodeFirstSync(input, optionsopt) → {ExtendedResults|any}
Decode the first CBOR item in the input, synchronously. This will throw
an exception if the input is not valid CBOR, or if there are more bytes
left over at the end (if options.extendedResults is not true).
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input |
BufferLike
|
If a Readable stream, must have received the `readable` event already, or you will get an error claiming "Insufficient data". | ||
options |
DecoderOptions
|
string
|
<optional> |
{} | Options or encoding for input. |
Throws:
-
-
Data is left over after decoding.
- Type
-
UnexpectedDataError
-
-
-
Insufficient data.
- Type
-
Error
-
(static) nullcheck(val) → {any}
Check the given value for a symbol encoding a NULL or UNDEFINED value in
the CBOR stream.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
val |
any
|
The value to check. |
Throws:
-
Nothing was found.
- Type
-
Error
Returns:
- Type:
-
any
The corrected value.
Example
myDecoder.on('data', val => {
val = Decoder.nullcheck(val)
// ...
})