Skip to content

Instantly share code, notes, and snippets.

@mikeal
Last active December 16, 2015 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeal/5471142 to your computer and use it in GitHub Desktop.
Save mikeal/5471142 to your computer and use it in GitHub Desktop.
Browserify BIG JSON test.
var fs = require('fs')
, path = require('path')
, http = require('http')
, browserify = require('browserify')
, request = require('request')
;
http.createServer(function (req, resp) {
resp.statusCode = 200
if (req.url === '/test.js') {
var b = browserify([path.join(__dirname, 'test.js')])
resp.setHeader('content-type', 'text/javascript')
b.bundle({debug: true}).pipe(resp)
} else if (req.url === '/') {
resp.setHeader('content-type', 'text/html')
resp.end('<html><script src="/test.js"></script></html>')
} else if (req.url === '/json') {
var r = request('http://isaacs.iriscouch.com/registry/_all_docs?include_docs=true')
r.on('data', function (chunk) {console.log(chunk.length)})
req.pipe(r).pipe(resp)
} else {
resp.statusCode = 404
resp.end()
}
}).listen(8080, function () {
console.log('http://localhost:8080/')
})
var http = require('http')
, JSONStream = require('JSONStream')
, assert = require('assert')
;
var window
if (typeof window === undefined) {
// http://isaacs.iriscouch.com/registry/_all_docs?include_docs=true
var opts =
{ host: 'isaacs.iriscouch.com'
, path: '/registry/_all_docs?include_docs=true'
, headers: {'accept':'application/json'}
}
} else {
window = window
var opts =
{ path: '/json'
, headers: {'accept':'application/json'}
}
}
var r = http.request(opts)
r.on('response', function (response) {
assert.equal(response.statusCode, 200)
response.on('data', function (c) {console.log(c.length)})
var j = JSONStream.parse('rows.*.doc')
j.on('data', console.log.bind(console))
response.pipe(j)
response.on('end', console.log.bind(console, 'end'))
})
r.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment