new Decoder()
Decode a stream of CBOR bytes by transforming them into equivalent
JavaScript data. Because of the limitations of Node object streams,
special symbols are emitted instead of NULL or UNDEFINED. Fix those
up by calling Decoder.nullcheck.
Extends
- BinaryParseStream
Classes
Methods
-
<static> decodeAll(input, options, cb)
-
Decode all of the CBOR items in the input. This will error if there are more bytes left over at the end.
Parameters:
Name Type Description inputstring | Buffer the input to parse optionsstring | Object Decoding options. If string, the input encoding. cbdecodeAllCallback Returns:
if no callback- Type
- Promise
-
<static> decodeAllSync(input [, options])
-
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.
Parameters:
Name Type Argument Default Description inputstring | Buffer optionsstring | Object <optional>
{encoding: 'hex'} Properties
Name Type Argument Description encoding: 'hex'string <optional>
The encoding of the input. Ignored if input is a Buffer. Returns:
- Array of all found items- Type
- Array
-
<static> decodeFirst(input, options, cb)
-
Decode the first CBOR item in the input. This will error if there are more bytes left over at the end, 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.
Parameters:
Name Type Description inputstring | Buffer the input to parse optionsfunction | string | Object Properties
Name Type Argument Description encoding: 'hex'string <optional>
The encoding of the input. Ignored if input is a Buffer. cbdecodeCallback Returns:
if no cb specified- Type
- Promise
-
<static> decodeFirstSync(input [, options])
-
Decode the first CBOR item in the input, synchronously. This will throw an exception if the input is not valid CBOR.
Parameters:
Name Type Argument Default Description inputstring | Buffer optionsobject <optional>
{encoding: 'hex'} Properties
Name Type Argument Description encoding: 'hex'string <optional>
The encoding of the input. Ignored if input is a Buffer. Returns:
- the decoded value- Type
- any
-
<static> nullcheck(val)
-
Check the given value for a symbol encoding a NULL or UNDEFINED value in the CBOR stream.
Parameters:
Name Type Description valany the value to check Returns:
the corrected value- Type
- any
Example
myDecoder.on('data', function(val) { val = Decoder.nullcheck(val); ... }); -
close()
-
Stop processing