code: function str2ab(stringToEncode, insertBom) {
        stringToEncode = stringToEncode.replace(/\r\n/g,"\n");
  
        var utftext = []
          , n
          , c
          ;
  
        if (true === insertBom)  {
          utftext[0] =  0xef;
          utftext[1] =  0xbb;
          utftext[2] =  0xbf;
        }
  
        for (n = 0; n < stringToEncode.length; n += 1) {
  
          c = stringToEncode.charCodeAt(n);
  
          if (c < 128) {
              utftext[utftext.length]= c;
          }
          else if((c > 127) && (c < 2048)) {
              utftext[utftext.length] = (c >> 6) | 192;
              utftext[utftext.length] = (c & 63) | 128;
          }
          else {
              utftext[utftext.length] = (c >> 12) | 224;
              utftext[utftext.length] = ((c >> 6) & 63) | 128;
              utftext[utftext.length] = (c & 63) | 128;
          }
  
        }
        return new Uint8Array(utftext).buffer;
      }
docs: convert from string to arraybuffer