44import  CborReader  from  'cbor-js' ; 
55import  PubNubCore  from  '../core/pubnub-common' ; 
66import  Networking  from  '../networking' ; 
7- import  CryptoJS   from  '../core/components/cryptography/hmac-sha256 ' ; 
7+ import  {   decode   }   from  '../core/components/base64_codec ' ; 
88import  Cbor  from  '../cbor/common' ; 
99import  {  del ,  get ,  post ,  patch ,  getfile ,  postfile  }  from  '../networking/modules/web-node' ; 
1010
@@ -19,38 +19,6 @@ function sendBeacon(url) {
1919  } 
2020} 
2121
22- function  base64ToBinary ( base64String )  { 
23-   const  parsedWordArray  =  CryptoJS . enc . Base64 . parse ( base64String ) . words ; 
24-   const  arrayBuffer  =  new  ArrayBuffer ( parsedWordArray . length  *  4 ) ; 
25-   const  view  =  new  Uint8Array ( arrayBuffer ) ; 
26-   let  filledArrayBuffer  =  null ; 
27-   let  zeroBytesCount  =  0 ; 
28-   let  byteOffset  =  0 ; 
29- 
30-   for  ( let  wordIdx  =  0 ;  wordIdx  <  parsedWordArray . length ;  wordIdx  +=  1 )  { 
31-     const  word  =  parsedWordArray [ wordIdx ] ; 
32-     byteOffset  =  wordIdx  *  4 ; 
33-     view [ byteOffset ]  =  ( word  &  0xff000000 )  >>  24 ; 
34-     view [ byteOffset  +  1 ]  =  ( word  &  0x00ff0000 )  >>  16 ; 
35-     view [ byteOffset  +  2 ]  =  ( word  &  0x0000ff00 )  >>  8 ; 
36-     view [ byteOffset  +  3 ]  =  word  &  0x000000ff ; 
37-   } 
38- 
39-   for  ( let  byteIdx  =  byteOffset  +  3 ;  byteIdx  >=  byteOffset ;  byteIdx  -=  1 )  { 
40-     if  ( view [ byteIdx ]  ===  0  &&  zeroBytesCount  <  3 )  { 
41-       zeroBytesCount  +=  1 ; 
42-     } 
43-   } 
44- 
45-   if  ( zeroBytesCount  >  0 )  { 
46-     filledArrayBuffer  =  view . buffer . slice ( 0 ,  view . byteLength  -  zeroBytesCount ) ; 
47-   }  else  { 
48-     filledArrayBuffer  =  view . buffer ; 
49-   } 
50- 
51-   return  filledArrayBuffer ; 
52- } 
53- 
5422function  stringifyBufferKeys ( obj )  { 
5523  const  isObject  =  ( value )  =>  value  &&  typeof  value  ===  'object'  &&  value . constructor  ===  Object ; 
5624  const  isString  =  ( value )  =>  typeof  value  ===  'string'  ||  value  instanceof  String ; 
@@ -99,7 +67,7 @@ export default class extends PubNubCore {
9967      getfile, 
10068      postfile, 
10169    } ) ; 
102-     setup . cbor  =  new  Cbor ( ( arrayBuffer )  =>  stringifyBufferKeys ( CborReader . decode ( arrayBuffer ) ) ,  base64ToBinary ) ; 
70+     setup . cbor  =  new  Cbor ( ( arrayBuffer )  =>  stringifyBufferKeys ( CborReader . decode ( arrayBuffer ) ) ,  decode ) ; 
10371
10472    setup . PubNubFile  =  PubNubFile ; 
10573    setup . cryptography  =  new  WebCryptography ( ) ; 
0 commit comments