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) {