Skip to content

Commit

Permalink
Define Body.arrayBuffer even if support.blob is false
Browse files Browse the repository at this point in the history
resolves #992
  • Loading branch information
Jake Champion authored and JakeChampion committed Jul 18, 2023
1 parent dffc542 commit d8669ab
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,27 @@ function Body() {
return Promise.resolve(new Blob([this._bodyText]))
}
}
}

this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
var isConsumed = consumed(this)
if (isConsumed) {
return isConsumed
}
if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
return Promise.resolve(
this._bodyArrayBuffer.buffer.slice(
this._bodyArrayBuffer.byteOffset,
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
)
this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
var isConsumed = consumed(this)
if (isConsumed) {
return isConsumed
} else 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)
return Promise.resolve(this._bodyArrayBuffer)
}
} else if (support.blob) {
return this.blob().then(readBlobAsArrayBuffer)
} else {
throw new Error('could not read as ArrayBuffer')
}
}

Expand Down

0 comments on commit d8669ab

Please sign in to comment.