diff --git a/guacamole-common-js/src/main/webapp/modules/StringReader.js b/guacamole-common-js/src/main/webapp/modules/StringReader.js index a2ce78b77..470f3af0c 100644 --- a/guacamole-common-js/src/main/webapp/modules/StringReader.js +++ b/guacamole-common-js/src/main/webapp/modules/StringReader.js @@ -39,11 +39,104 @@ Guacamole.StringReader = function(stream) { */ var guac_reader = this; - // Receive blobs as strings - stream.onblob = function(data) { + /** + * Wrapped Guacamole.ArrayBufferReader. + * @private + * @type Guacamole.ArrayBufferReader + */ + var array_reader = new Guacamole.ArrayBufferReader(stream); - // Convert to string - var text = window.atob(data); + /** + * The number of bytes remaining for the current codepoint. + * + * @type Number + */ + var bytes_remaining = 0; + + /** + * The current codepoint value, as calculated from bytes read so far. + * @type Number + */ + var codepoint = 0; + + /** + * Decodes the given UTF-8 data into a Unicode string. The data may end in + * the middle of a multibyte character. + * + * @private + * @param {ArrayBuffer} buffer Arbitrary UTF-8 data. + * @return {String} A decoded Unicode string. + */ + function __decode_utf8(buffer) { + + var text = ""; + + var bytes = new Uint8Array(buffer); + for (var i=0; i