66 */
77
88import { convert } from 'encoding' ;
9- import bodyStream from 'is-stream' ;
10- import toArrayBuffer from 'buffer-to-arraybuffer' ;
11- import { PassThrough } from 'stream' ;
9+ import Stream , { PassThrough } from 'stream' ;
1210import Blob , { BUFFER } from './blob.js' ;
1311import FetchError from './fetch-error.js' ;
1412
@@ -36,7 +34,7 @@ export default function Body(body, {
3634 // body is blob
3735 } else if ( Buffer . isBuffer ( body ) ) {
3836 // body is buffer
39- } else if ( bodyStream ( body ) ) {
37+ } else if ( body instanceof Stream ) {
4038 // body is stream
4139 } else {
4240 // none of the above
@@ -60,7 +58,7 @@ Body.prototype = {
6058 * @return Promise
6159 */
6260 arrayBuffer ( ) {
63- return consumeBody . call ( this ) . then ( buf => toArrayBuffer ( buf ) ) ;
61+ return consumeBody . call ( this ) . then ( buf => buf . buffer . slice ( buf . byteOffset , buf . byteOffset + buf . byteLength ) ) ;
6462 } ,
6563
6664 /**
@@ -164,7 +162,7 @@ function consumeBody(body) {
164162 }
165163
166164 // istanbul ignore if: should never happen
167- if ( ! bodyStream ( this . body ) ) {
165+ if ( ! ( this . body instanceof Stream ) ) {
168166 return Body . Promise . resolve ( new Buffer ( 0 ) ) ;
169167 }
170168
@@ -292,7 +290,7 @@ export function clone(instance) {
292290
293291 // check that body is a stream and not form-data object
294292 // note: we can't clone the form-data object without having it as a dependency
295- if ( bodyStream ( body ) && typeof body . getBoundary !== 'function' ) {
293+ if ( ( body instanceof Stream ) && ( typeof body . getBoundary !== 'function' ) ) {
296294 // tee instance body
297295 p1 = new PassThrough ( ) ;
298296 p2 = new PassThrough ( ) ;
0 commit comments