From df26918b3d39ac803ecc5020c92e5a7d8c3d88b3 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Wed, 16 Sep 2015 21:23:11 +0500 Subject: [PATCH] throw when callback is passed to stream mode --- index.js | 6 +++++- test/test-stream.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3ac5d19..cc39c3e 100644 --- a/index.js +++ b/index.js @@ -288,7 +288,11 @@ helpers.forEach(function (el) { }; }); -got.stream = function (url, opts) { +got.stream = function (url, opts, cb) { + if (cb || typeof opts === 'function') { + throw new Error('callback can not be used with stream mode'); + } + return asStream(normalizeArguments(url, opts)); }; diff --git a/test/test-stream.js b/test/test-stream.js index b8cbef8..00a0dd6 100644 --- a/test/test-stream.js +++ b/test/test-stream.js @@ -37,6 +37,18 @@ test('json option can not be used in stream mode', function (t) { t.end(); }); +test('callback can not be used in stream mode', function (t) { + t.throws(function () { + got.stream(s.url, {json: true}, function () {}); + }, 'callback can not be used in stream mode'); + + t.throws(function () { + got.stream(s.url, function () {}); + }, 'callback can not be used in stream mode'); + + t.end(); +}); + test('return readable stream', function (t) { got.stream(s.url) .on('data', function (data) {