0.1.2 • Published 11 years ago

json-array-stream v0.1.2

Weekly downloads
11
License
-
Repository
github
Last release
11 years ago

JSON Array Stream Build Status

Example

The main use case for this is to stream a MongoDB query to a web client. This is to be used only with streaming arrays, not objects.

var streamify = require('json-array-stream')

app.get('/things', function (req, res, next) {
  res.setHeader('Content-Type', 'application/json; charset=utf-8')

  db.things.find()
  .stream()
  .pipe(streamify())
  .pipe(res)
})

will yield something like

[
{"_id":"123412341234123412341234"}
,
{"_id":"123412341234123412341234"}
]

Separators

  • The stream always starts with '[\n'.
  • Documents are separated by '\n,\n'.
  • The stream is terminated with '\n]'.

API

streamify()

Returns a duplex stream.

License

WTFPL

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago