lib/index.js
function fetchStream() {
	var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
	var callback = arguments[1];

	var cb = callback;
	var stream = null;
	if (cb === undefined) {
		stream = makeStream();
		cb = stream.handler;
	}
	var url = typeof options === 'string' ? options : options.url || options.path;
	if (supportFetch) {
		// TODO support Request object?
		var init = (typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object' ? options : {};
		fetch(url, init).then(function (res) {
			if (res.status >= 200 && res.status < 300) {
				pump(res.body.getReader(), (0, _parser2.default)(cb));
			} else {
				// TODO read custom error payload
				cb(null, { status: res.status, statusText: res.statusText });
			}
		}, function (err) {
			cb(null, err);
		});
	} else {
		(function () {
			var parser = (0, _parser2.default)(cb, _parser.BUFFER);
			var opts = (typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object' ? _extends({}, options) : {};
			opts.path = url;
			var req = _streamHttp2.default.get(opts, function (res) {
				var status = res.status || res.statusCode;
				if (!(status >= 200 && status < 300)) {
					// TODO read custom error payload
					cb(null, { status: status, statusText: res.statusText || res.statusMessage });
					return;
				}

				res.on('data', function (buf) {
					if (parser(buf) === false) {
						// cancelling
						req.abort();
					}
				});

				res.on('error', function (err) {
					req.abort();
					cb(null, err);
				});
			});
		})();
	}
	return stream;
}
function fetchStream() {
	var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
	var callback = arguments[1];

	var cb = callback;
	var stream = null;
	if (cb === undefined) {
		stream = makeStream();
		cb = stream.handler;
	}
	var url = typeof options === 'string' ? options : options.url || options.path;
	if (supportFetch) {
		// TODO support Request object?
		var init = (typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object' ? options : {};
		fetch(url, init).then(function (res) {
			if (res.status >= 200 && res.status < 300) {
				pump(res.body.getReader(), (0, _parser2.default)(cb));
			} else {
				// TODO read custom error payload
				cb(null, { status: res.status, statusText: res.statusText });
			}
		}, function (err) {
			cb(null, err);
		});
	} else {
		(function () {
			var parser = (0, _parser2.default)(cb, _parser.BUFFER);
			var opts = (typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object' ? _extends({}, options) : {};
			opts.path = url;
			var req = _streamHttp2.default.get(opts, function (res) {
				var status = res.status || res.statusCode;
				if (!(status >= 200 && status < 300)) {
					// TODO read custom error payload
					cb(null, { status: status, statusText: res.statusText || res.statusMessage });
					return;
				}

				res.on('data', function (buf) {
					if (parser(buf) === false) {
						// cancelling
						req.abort();
					}
				});

				res.on('error', function (err) {
					req.abort();
					cb(null, err);
				});
			});
		})();
	}
	return stream;
}
function fetchStream ( ) { var options = arguments . length <= 0 || arguments [ 0 ] === undefined ? { } : arguments [ 0 ] ; var callback = arguments [ 1 ] ; var cb = callback ; var stream = null ; if ( cb === undefined ) { stream = makeStream ( ) ; cb = stream . handler ; } var url = typeof options === 'string' ? options : options . url || options . path ; if ( supportFetch ) { // TODO support Request object? var init = ( typeof options === 'undefined' ? 'undefined' : _typeof ( options ) ) === 'object' ? options : { } ; fetch ( url , init ) . then ( function ( res ) { if ( res . status >= 200 && res . status < 300 ) { pump ( res . body . getReader ( ) , ( 0 , _parser2 . default ) ( cb ) ) ; } else { // TODO read custom error payload cb ( null , { status : res . status , statusText : res . statusText } ) ; } } , function ( err ) { cb ( null , err ) ; } ) ; } else { ( function ( ) { var parser = ( 0 , _parser2 . default ) ( cb , _parser . BUFFER ) ; var opts = ( typeof options === 'undefined' ? 'undefined' : _typeof ( options ) ) === 'object' ? _extends ( { } , options ) : { } ; opts . path = url ; var req = _streamHttp2 . default . get ( opts , function ( res ) { var status = res . status || res . statusCode ; if ( ! ( status >= 200 && status < 300 ) ) { // TODO read custom error payload cb ( null , { status : status , statusText : res . statusText || res . statusMessage } ) ; return ; } res . on ( 'data' , function ( buf ) { if ( parser ( buf ) === false ) { // cancelling req . abort ( ) ; } } ) ; res . on ( 'error' , function ( err ) { req . abort ( ) ; cb ( null , err ) ; } ) ; } ) ; } ) ( ) ; } return stream ; }
Fetches resource stream.
@param  {object} [options] URL or options of request.
@param  {function} [callback] The callback to process each chunk in the stream.
Fetches resource stream .