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 6f84db9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion fetch.js
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

3 comments on commit 6f84db9

@Googlnew
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch.js

@Googlnew
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Googlnew
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.