hildjj / node-cbor

Encode and decode CBOR documents, with both easy mode, streaming mode, and SAX-style evented mode.
MIT License
356 stars 73 forks source link

Cbor <> CborWeb issue #185

Open astanciu opened 11 months ago

astanciu commented 11 months ago

I'm sing cbor-web and another library (cose-js) which uses cbor, and notice some issues packing between the two. I've narrowed down the issue to this:

  const cbor = require("cbor");
  const cborWeb = require("cbor-web");

  const data = cborWeb.encode('hello')    // Uint8Array
  const encoded = cbor.encode(data)       // Buffer
  const decoded = cbor.decode(encoded)    // ByteObject -> {0: 101, 1:104, etc...}

  // which causes this to fail
  const dataDecoded = cborWeb.decode(decoded)  

Not sure what's going on here, is this something I can address on my side in some way?

hildjj commented 11 months ago

It's likely different values for the preferWeb setting. true gets you Uint8Array. false gets you Buffer. ByteObject is likely some weird webpack'd version of Buffer.