# buffered-xhr-stream

> A pausable/resumable xhr stream

Latest version **0.1.6** (published 2020-07-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install buffered-xhr-stream
pnpm add buffered-xhr-stream
yarn add buffered-xhr-stream
bun add buffered-xhr-stream
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2020-07-02 |
| First published | 2014-06-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Nathan Bowser |
| Maintainers | koopa |
| Keywords | xhr, xhr-stream, stream, buffered-stream |

## Links

- npm: https://www.npmjs.com/package/buffered-xhr-stream
- Repository: https://github.com/SpiderStrategies/node-buffered-xhr-stream
- Issues: https://github.com/SpiderStrategies/node-buffered-xhr-stream/issues
- npm.io page: https://npm.io/package/buffered-xhr-stream

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2020-07-02
- 0.1.5 — 2016-03-17
- 0.1.4 — 2014-06-18
- 0.1.3 — 2014-06-16
- 0.1.2 — 2014-06-13
- 0.1.1 — 2014-06-13
- 0.1.0 — 2014-06-13

## README

# 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

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

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

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

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

// 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 additional options when initializing.

When using the xhr option:

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

xhr.open('GET', '/some-large-docs.json', true)
var stream = new XHRStream({ xhr: 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
})
```

---
_Source: https://npm.io/package/buffered-xhr-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
