Remove unneeded is-stream and buffer-to-arraybuffer (#241)

This commit is contained in:
Tino Vyatkin 2017-02-26 22:29:57 -04:00 committed by Timothy Gu
parent e284841db9
commit f0d0675d00
2 changed files with 6 additions and 10 deletions

View File

@ -57,8 +57,6 @@
},
"dependencies": {
"babel-runtime": "^6.11.6",
"buffer-to-arraybuffer": "0.0.4",
"encoding": "^0.1.11",
"is-stream": "^1.0.1"
"encoding": "^0.1.11"
}
}

View File

@ -6,9 +6,7 @@
*/
import {convert} from 'encoding';
import bodyStream from 'is-stream';
import toArrayBuffer from 'buffer-to-arraybuffer';
import {PassThrough} from 'stream';
import Stream, {PassThrough} from 'stream';
import Blob, {BUFFER} from './blob.js';
import FetchError from './fetch-error.js';
@ -36,7 +34,7 @@ export default function Body(body, {
// body is blob
} else if (Buffer.isBuffer(body)) {
// body is buffer
} else if (bodyStream(body)) {
} else if (body instanceof Stream) {
// body is stream
} else {
// none of the above
@ -60,7 +58,7 @@ Body.prototype = {
* @return Promise
*/
arrayBuffer() {
return consumeBody.call(this).then(buf => toArrayBuffer(buf));
return consumeBody.call(this).then(buf => buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
},
/**
@ -164,7 +162,7 @@ function consumeBody(body) {
}
// istanbul ignore if: should never happen
if (!bodyStream(this.body)) {
if (!(this.body instanceof Stream)) {
return Body.Promise.resolve(new Buffer(0));
}
@ -292,7 +290,7 @@ export function clone(instance) {
// check that body is a stream and not form-data object
// note: we can't clone the form-data object without having it as a dependency
if (bodyStream(body) && typeof body.getBoundary !== 'function') {
if ((body instanceof Stream) && (typeof body.getBoundary !== 'function')) {
// tee instance body
p1 = new PassThrough();
p2 = new PassThrough();