提交 1ddcadb2 编写于 作者: M Mislav Marohnić

Fix reading ArrayBuffer into string on older browsers

Android 4.0 doesn't like the `String.fromCharCode.apply` hack.
上级 76f6a09c
...@@ -186,6 +186,16 @@ ...@@ -186,6 +186,16 @@
return promise return promise
} }
function readArrayBufferAsText(buf) {
var view = new Uint8Array(buf)
var chars = new Array(view.length)
for (var i = 0; i < view.length; i++) {
chars[i] = String.fromCharCode(view[i])
}
return chars.join('')
}
function bufferClone(buf) { function bufferClone(buf) {
if (buf.slice) { if (buf.slice) {
return buf.slice(0) return buf.slice(0)
...@@ -260,9 +270,7 @@ ...@@ -260,9 +270,7 @@
if (this._bodyBlob) { if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob) return readBlobAsText(this._bodyBlob)
} else if (this._bodyArrayBuffer) { } else if (this._bodyArrayBuffer) {
var view = new Uint8Array(this._bodyArrayBuffer) return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
var str = String.fromCharCode.apply(null, view)
return Promise.resolve(str)
} else if (this._bodyFormData) { } else if (this._bodyFormData) {
throw new Error('could not read FormData body as text') throw new Error('could not read FormData body as text')
} else { } else {
......
...@@ -64,7 +64,13 @@ function arrayBufferFromText(text) { ...@@ -64,7 +64,13 @@ function arrayBufferFromText(text) {
} }
function readArrayBufferAsText(buf) { function readArrayBufferAsText(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf)) var view = new Uint8Array(buf)
var chars = new Array(view.length)
for (var i = 0; i < view.length; i++) {
chars[i] = String.fromCharCode(view[i])
}
return chars.join('')
} }
var native = {} var native = {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册