chensenlai 10988628a0 语音房项目初始化 | 5 роки тому | |
---|---|---|
.. | ||
LICENSE | 5 роки тому | |
README.md | 5 роки тому | |
index.js | 5 роки тому | |
package.json | 5 роки тому |
Similar to JSONStream.stringify() except it is, by default, a binary stream, and it is a streams2 implementation.
The main use case for this is to stream a database query to a web client. This is meant to be used only with arrays, not objects.
var Stringify = require('streaming-json-stringify')
app.get('/things', function (req, res, next) {
res.setHeader('Content-Type', 'application/json; charset=utf-8')
db.things.find()
.stream()
.pipe(Stringify())
.pipe(res)
})
will yield something like
[
{"_id":"123412341234123412341234"}
,
{"_id":"123412341234123412341234"}
]
'[\n'
.'\n,\n'
.'\n]\n'
.By default, json-stringify-safe is used to convert objects into strings. This can be configured with options.stringifier
.
Returns a Transform
stream.
The options are passed to the Transform
constructor.
You can override these:
var stringify = Stringify()
stringify.replacer = function () {}
stringify.space = 2
stringify.opener = '['
stringify.seperator = ','
stringify.closer = ']'
stringify.stringifier = JSON.stringify