@@ -13,11 +13,6 @@ const kReading = Symbol('kReading')
1313const kBody = Symbol ( 'kBody' )
1414const kAbort = Symbol ( 'abort' )
1515
16- const kTextType = 1
17- const kBlobType = 2
18- const kArrayBufferType = 3
19- const kJSONType = 4
20-
2116module . exports = class BodyReadable extends Readable {
2217 constructor ( resume , abort ) {
2318 super ( { autoDestroy : true , read : resume } )
@@ -100,22 +95,22 @@ module.exports = class BodyReadable extends Readable {
10095
10196 // https://fetch.spec.whatwg.org/#dom-body-text
10297 text ( ) {
103- return consume ( this , kTextType )
98+ return consume ( this , 'text' )
10499 }
105100
106101 // https://fetch.spec.whatwg.org/#dom-body-json
107102 json ( ) {
108- return consume ( this , kJSONType )
103+ return consume ( this , 'json' )
109104 }
110105
111106 // https://fetch.spec.whatwg.org/#dom-body-blob
112107 blob ( ) {
113- return consume ( this , kBlobType )
108+ return consume ( this , 'blob' )
114109 }
115110
116111 // https://fetch.spec.whatwg.org/#dom-body-arraybuffer
117112 arrayBuffer ( ) {
118- return consume ( this , kArrayBufferType )
113+ return consume ( this , 'arrayBuffer' )
119114 }
120115
121116 // https://fetch.spec.whatwg.org/#dom-body-formdata
@@ -189,7 +184,6 @@ async function consume (stream, type) {
189184 } )
190185 . on ( 'close' , function ( ) {
191186 if ( this [ kConsume ] . body !== null ) {
192- // TODO: Use Node error?
193187 consumeFinish ( this [ kConsume ] , new RequestAbortedError ( ) )
194188 }
195189 } )
@@ -228,11 +222,11 @@ function consumeEnd (consume) {
228222 const { type, body, resolve, stream, length } = consume
229223
230224 try {
231- if ( type === kTextType ) {
225+ if ( type === 'text' ) {
232226 resolve ( body . join ( '' ) )
233- } else if ( type === kJSONType ) {
227+ } else if ( type === 'json' ) {
234228 resolve ( JSON . parse ( body . join ( '' ) ) )
235- } else if ( type === kArrayBufferType ) {
229+ } else if ( type === 'arrayBuffer' ) {
236230 const dst = new Uint8Array ( length )
237231
238232 let pos = 0
@@ -242,7 +236,7 @@ function consumeEnd (consume) {
242236 }
243237
244238 resolve ( dst )
245- } else if ( type === kBlobType ) {
239+ } else if ( type === 'blob' ) {
246240 if ( ! Blob ) {
247241 Blob = require ( 'buffer' ) . Blob
248242 }
0 commit comments