code: function str2ab (str) {
    var buf = new ArrayBuffer(str.length * 2) // 2 bytes for each char
    var bufView = new Uint16Array(buf)
    for (var i = 0, strLen = str.length; i < strLen; i++) {
      bufView[i] = str.charCodeAt(i)
    }
    return new Uint8Array(buf)
    /*var idx, len = str.length, arr = new Array( len );
     for ( idx = 0 ; idx < len ; ++idx ) {
         arr[ idx ] = str.charCodeAt(idx) & 0xFF;
     }
     // You may create an ArrayBuffer from a standard array (of values) as follows:
     return new Uint8Array( arr )*/
  }
docs: taken from http://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers