diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-07-30 14:21:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-07-30 14:21:39 -0700 |
commit | d04125d12a2c8656c30dbe58ba82719a361a0580 (patch) | |
tree | b52beb210843270ddcecdd820c6ec036980ae81d | |
parent | e1f51c6d670ff74b16c3ceeef96af1bca5f02f0e (diff) |
improve support for binary xhrs
-rw-r--r-- | src/library.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js index 18988de6..604c742f 100644 --- a/src/library.js +++ b/src/library.js @@ -264,10 +264,15 @@ LibraryManager.library = { // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available. var xhr = new XMLHttpRequest(); xhr.open('GET', obj.url, false); - xhr.overrideMimeType('text/plain; charset=x-user-defined'); // Binary. + xhr.responseType = 'arraybuffer'; // hint to the browser that we want binary data + xhr.overrideMimeType('text/plain; charset=x-user-defined'); // another hint xhr.send(null); if (xhr.status != 200 && xhr.status != 0) success = false; - obj.contents = intArrayFromString(xhr.responseText || '', true); + if (xhr.response) { + obj.contents = new Uint8Array(xhr.response); + } else { + obj.contents = intArrayFromString(xhr.responseText || '', true); + } } else if (typeof read !== 'undefined') { // Command-line. try { |