Skip to content

Commit

Permalink
Make Response.arrayBuffer() always resolve with a ArrayBuffer
Browse files Browse the repository at this point in the history
Fixes #801
  • Loading branch information
JakeChampion committed Jul 31, 2020
1 parent 19a2ff0 commit 21bbcbf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,15 @@ function Body() {

this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
consumed(this)
if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
return Promise.resolve(this._bodyArrayBuffer.buffer.slice(
this._bodyArrayBuffer.byteOffset,
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
))
} else {
return Promise.resolve(this._bodyArrayBuffer)
}
} else {
return this.blob().then(readBlobAsArrayBuffer)
}
Expand Down

0 comments on commit 21bbcbf

Please sign in to comment.