• An object containing a Unit8Array is written to flash and read back again.
    I think I read somewhere thatthe atob and btoa functions operate on 4 byte increments and you have to pad the length to a integer multiple of 4.
    var A=new Uint8Array(8) will work. var A=new Uint8Array(7) won't.
    Give it a try anyway.

    console.log("Create an object with an Uint8Array");
    var A={B:10,C:new Uint8Array(16)};
    for(i=0;i<16;i++)A.C[i]=i;
    console.log("A= ",A);
    

    The output:

    >echo(0);
    Create an object with an Uint8Array
    A=  { "B": 10,
      "C": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
     }
    Stringify the object
    D=  {"B":10,"C":new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])}
    Parse it back returns undefined
    F=  undefined
    apply btoa trick
    A=  { "B": 10,
      "C": "AAECAwQFBgcICQoLDA0ODw=="
     }
    stringify
    D=  {"B":10,"C":"AAECAwQFBgcICQoLDA0ODw=="}
    Write D to flash
    Read G from flash
    G=  new Uint8Array([123, 34, 66, 34, 58, 49, 48, 44, 34, 67, 34, 58, 34, 65, 65, 69, 67, 65, 119, 81, 70, 66, 103, 99, 73, 67, 81, 111, 76, 68, 65, 48, 79, 68, 119, 61, 61, 34, 125])
    parse G into H
    H=  { "B": 10,
      "C": "AAECAwQFBgcICQoLDA0ODw=="
     }
    reverse the trick
    H=  { "B": 10,
      "C": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
     }
    

    1 Attachment

About