1 | var Transform = require('stream').Transform;
|
2 | var BSON = require('bson');
|
3 | var bson = new BSON();
|
4 |
|
5 | module.exports = function rawTransform(raw) {
|
6 |
|
7 |
|
8 | function transform(chunk, encoding, cb) {
|
9 |
|
10 | if (raw) {
|
11 | var response = bson.deserialize(chunk);
|
12 | response.cursor.firstBatch.forEach(function(doc) {
|
13 | this.push(bson.serialize(doc));
|
14 | }.bind(this));
|
15 | return cb();
|
16 | }
|
17 |
|
18 | return cb(null, chunk);
|
19 | }
|
20 |
|
21 | return new Transform({
|
22 | readableObjectMode: true,
|
23 | writableObjectMode: true,
|
24 | transform: transform
|
25 | });
|
26 | };
|