New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fetch-stream

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-stream

Easy fetch of HTTP/1.1 chunked content.

latest
Source
npmnpm
Version
0.6.5
Version published
Maintainers
1
Created
Source

npm version Build Status codecov.io Total downloads

fetch-stream

Easy fetch of HTTP/1.1 chunked content.

Basic usage

import fetchStream from 'fetch-stream';

const handler = (result) => {
	if (result.done) {
		console.log('completed');
		return;
	}
	console.log(result.value);
	return i < 100; // return false to cancel
};

fetchStream('/api/stream', handler);

Usage of stream API

import fetchStream from 'fetch-stream';

const handler = (result) => {
	if (result.done) {
		console.log('completed');
		return;
	}
	console.log(result.value);
	return i < 100; // return false to cancel
};

const stream = fetchStream('/api/stream');

const pump = () => {
	stream.read().then((result) => {
		if (result.done) {
			return;
		}
		if (handler(result) === false) {
			stream.cancel();
			return;
		}
		pump();
	});
};

// process all chunks
pump();

Keywords

fetch

FAQs

Package last updated on 04 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts