Socket
Socket
Sign inDemoInstall

buffered-xhr-stream

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 0.1.6

3

index.js

@@ -44,3 +44,4 @@ var stream = require('stream')

} else if (this.xhr.readyState === XMLHttpRequest.DONE) {
if (this.xhr.status >= 400) {
// A zero status can occur if there is no internet connection
if (this.xhr.status >= 400 || this.xhr.status == 0) {
var e = new Error(this.xhr.statusText || this.xhr.status)

@@ -47,0 +48,0 @@ e.xhr = this.xhr

{
"name": "buffered-xhr-stream",
"version": "0.1.5",
"version": "0.1.6",
"description": "A pausable/resumable xhr stream",

@@ -5,0 +5,0 @@ "main": "index.js",

# buffered-xhr-stream
A node stream that wraps xhr GET requests as a stream.
A node stream that wraps xhr GET requests as a stream.

@@ -15,3 +15,3 @@ 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.

var stream = new XHRStream(xhr)
var stream = new XHRStream({ xhr: xhr })
, count = 0

@@ -26,5 +26,22 @@

// or
var XHRStream = require('buffered-xhr-stream')
var stream = new XHRStream({ url: 'http://some-large-docs.json' })
, count = 0
stream.on('data', function (d) {
if (++count % 10 === 0) {
stream.pause()
}
console.log(d)
})
```
You can specify an optional chunk size.
You can specify additional options when initializing.
When using the xhr option:
```javascript

@@ -35,4 +52,16 @@ var XHRStream = require('buffered-xhr-stream')

xhr.open('GET', '/some-large-docs.json', true)
var stream = new XHRStream({ xhr: xhr, chunkSize: 2048 })
```
var stream = new XHRStream(xhr, {chunkSize: 2048})
When using the url option
```javascript
var XHRStream = require('buffered-xhr-stream')
var stream = new XHRStream({
url: 'http://some-large-docs.json',
method: 'GET',
contentType: 'application/json',
data: 'data passed to xhr.send()',
chunkSize: 2048
})
```
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc