Skip to content
This repository was archived by the owner on Aug 18, 2022. It is now read-only.

Commit f0d0675

Browse files
tinovyatkinTimothyGu
authored andcommitted
Remove unneeded is-stream and buffer-to-arraybuffer (node-fetch#241)
1 parent e284841 commit f0d0675

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757
},
5858
"dependencies": {
5959
"babel-runtime": "^6.11.6",
60-
"buffer-to-arraybuffer": "0.0.4",
61-
"encoding": "^0.1.11",
62-
"is-stream": "^1.0.1"
60+
"encoding": "^0.1.11"
6361
}
6462
}

src/body.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
*/
77

88
import {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';
1210
import Blob, {BUFFER} from './blob.js';
1311
import 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

Comments
 (0)