@@ -13,11 +13,6 @@ const kReading = Symbol('kReading')
13
13
const kBody = Symbol ( 'kBody' )
14
14
const kAbort = Symbol ( 'abort' )
15
15
16
- const kTextType = 1
17
- const kBlobType = 2
18
- const kArrayBufferType = 3
19
- const kJSONType = 4
20
-
21
16
module . exports = class BodyReadable extends Readable {
22
17
constructor ( resume , abort ) {
23
18
super ( { autoDestroy : true , read : resume } )
@@ -100,22 +95,22 @@ module.exports = class BodyReadable extends Readable {
100
95
101
96
// https://fetch.spec.whatwg.org/#dom-body-text
102
97
text ( ) {
103
- return consume ( this , kTextType )
98
+ return consume ( this , 'text' )
104
99
}
105
100
106
101
// https://fetch.spec.whatwg.org/#dom-body-json
107
102
json ( ) {
108
- return consume ( this , kJSONType )
103
+ return consume ( this , 'json' )
109
104
}
110
105
111
106
// https://fetch.spec.whatwg.org/#dom-body-blob
112
107
blob ( ) {
113
- return consume ( this , kBlobType )
108
+ return consume ( this , 'blob' )
114
109
}
115
110
116
111
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer
117
112
arrayBuffer ( ) {
118
- return consume ( this , kArrayBufferType )
113
+ return consume ( this , 'arrayBuffer' )
119
114
}
120
115
121
116
// https://fetch.spec.whatwg.org/#dom-body-formdata
@@ -189,7 +184,6 @@ async function consume (stream, type) {
189
184
} )
190
185
. on ( 'close' , function ( ) {
191
186
if ( this [ kConsume ] . body !== null ) {
192
- // TODO: Use Node error?
193
187
consumeFinish ( this [ kConsume ] , new RequestAbortedError ( ) )
194
188
}
195
189
} )
@@ -228,11 +222,11 @@ function consumeEnd (consume) {
228
222
const { type, body, resolve, stream, length } = consume
229
223
230
224
try {
231
- if ( type === kTextType ) {
225
+ if ( type === 'text' ) {
232
226
resolve ( body . join ( '' ) )
233
- } else if ( type === kJSONType ) {
227
+ } else if ( type === 'json' ) {
234
228
resolve ( JSON . parse ( body . join ( '' ) ) )
235
- } else if ( type === kArrayBufferType ) {
229
+ } else if ( type === 'arrayBuffer' ) {
236
230
const dst = new Uint8Array ( length )
237
231
238
232
let pos = 0
@@ -242,7 +236,7 @@ function consumeEnd (consume) {
242
236
}
243
237
244
238
resolve ( dst )
245
- } else if ( type === kBlobType ) {
239
+ } else if ( type === 'blob' ) {
246
240
if ( ! Blob ) {
247
241
Blob = require ( 'buffer' ) . Blob
248
242
}
0 commit comments