Strange behavior when using TextDecoder
Issue Description
The textDecoder has strange behavior when working with cbor data.
In node, it is working as expected but in nativescript the TextDecoder returns a strange format:
https://github.com/NativeScript/NativeScript/blob/17c85107ba84953630b0471c1f6f3d68f6d59f76/packages/core/text/text-common.ts#L70
More info:
Issue in node-cbor
Reproduction
https://github.com/abdallahkadour/cbor-node-ns-example
A code snippet will be executed in the app component.
clone and
$ns run ios
It executes the code:
import * as process from "process";
global.process = process;
import * as prereqs from "cbor-rn-prereqs";
import * as cbor from "cbor";
let object = {
"1": "DE",
"6": 1622316073,
"4": 1643356073,
};
console.log(
"The object ",
object,
" Will be encoded and decoded using cbor"
);
let encoded = cbor.encode(object);
console.log("The encode object hex ", encoded.toString("hex"));
console.log("The encode object ", encoded);
let decoded = cbor.decode(encoded);
let decodedString = JSON.stringify(decoded);
console.log("the decoded string", decodedString);
Relevant log output (if applicable)
The decoded object should be `{
"1": "DE",
"6": 1622316073,
"4": 1643356073,
};`
Thanks a lot for reporting this. I have also taken a look in cbor repo discussion about it and I can confirm NS polyfill for these 2 classes is incomplete or outdated. There is already been a small discussion with another member and I believe we'll look into this. Until then, I suggest that you use a 3rd-party polyfill for those if possible.
As a workaround, the library cbor-sync could be used.