Socket
Socket
Sign inDemoInstall

buffered-xhr-stream

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffered-xhr-stream

A pausable/resumable xhr stream


Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

buffered-xhr-stream

A node stream that wraps xhr GET requests as a stream.

Created because the browserify node http module emits all the data as it's received, and it cannot be paused. This can cause the browser to peg the cpu if it's a large request. This module allows you to pause the stream, so it stops emitting data events. XHR responseText is buffered anyway, so when this stream is resumed, it starts emitting buffered data stored in responseText.

USAGE

var XHRStream = require('buffered-xhr-stream')
  , xhr = new XMLHttpRequest

xhr.open('GET', '/some-large-docs.json', true)

var stream = new XHRStream(xhr)
  , count = 0

stream.on('data', function (d) {
  if (++count % 10 === 0) {
    stream.pause()
  }
  console.log(d)
})

You can specify an optional chunk size.

var XHRStream = require('buffered-xhr-stream')
  , xhr = new XMLHttpRequest

xhr.open('GET', '/some-large-docs.json', true)

var stream = new XHRStream(xhr, {chunkSize: 2048})

Keywords

FAQs

Package last updated on 17 Mar 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc