Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 30, 2021
1 parent 2e2f7ff commit e0872dd
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ const kReading = Symbol('kReading')
const kBody = Symbol('kBody')
const kAbort = Symbol('abort')

const kTextType = 1
const kBlobType = 2
const kArrayBufferType = 3
const kJSONType = 4

module.exports = class BodyReadable extends Readable {
constructor (resume, abort) {
super({ autoDestroy: true, read: resume })
Expand Down Expand Up @@ -100,22 +95,22 @@ module.exports = class BodyReadable extends Readable {

// https://fetch.spec.whatwg.org/#dom-body-text
text () {
return consume(this, kTextType)
return consume(this, 'text')
}

// https://fetch.spec.whatwg.org/#dom-body-json
json () {
return consume(this, kJSONType)
return consume(this, 'json')
}

// https://fetch.spec.whatwg.org/#dom-body-blob
blob () {
return consume(this, kBlobType)
return consume(this, 'blob')
}

// https://fetch.spec.whatwg.org/#dom-body-arraybuffer
arrayBuffer () {
return consume(this, kArrayBufferType)
return consume(this, 'arrayBuffer')
}

// https://fetch.spec.whatwg.org/#dom-body-formdata
Expand Down Expand Up @@ -228,11 +223,11 @@ function consumeEnd (consume) {
const { type, body, resolve, stream, length } = consume

try {
if (type === kTextType) {
if (type === 'text') {
resolve(body.join(''))
} else if (type === kJSONType) {
} else if (type === 'json') {
resolve(JSON.parse(body.join('')))
} else if (type === kArrayBufferType) {
} else if (type === 'arrayBuffer') {
const dst = new Uint8Array(length)

let pos = 0
Expand All @@ -242,7 +237,7 @@ function consumeEnd (consume) {
}

resolve(dst)
} else if (type === kBlobType) {
} else if (type === 'blob') {
if (!Blob) {
Blob = require('buffer').Blob
}
Expand Down

0 comments on commit e0872dd

Please sign in to comment.