diff --git a/lib/api/readable.js b/lib/api/readable.js index cc174133994..b57b2b58a70 100644 --- a/lib/api/readable.js +++ b/lib/api/readable.js @@ -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 }) @@ -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 @@ -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 @@ -242,7 +237,7 @@ function consumeEnd (consume) { } resolve(dst) - } else if (type === kBlobType) { + } else if (type === 'blob') { if (!Blob) { Blob = require('buffer').Blob }