stream-json
Advanced tools
Comparing version
@@ -28,3 +28,2 @@ 'use strict'; | ||
'streamNumbers' in options && (this._streamNumbers = options.streamNumbers); | ||
this._jsonStreaming = options.jsonStreaming; | ||
} | ||
@@ -31,0 +30,0 @@ !this._packKeys && (this._streamKeys = true); |
{ | ||
"name": "stream-json", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"description": "stream-json is the micro-library of Node.js stream components for creating custom JSON processing pipelines with a minimal memory footprint. It can parse JSON files far exceeding available memory streaming individual primitives using a SAX-inspired API. Includes utilities to stream JSON database dumps.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/uhop/stream-json", |
@@ -113,2 +113,3 @@ # stream-json | ||
- 1.4.0 *added `makeArray` functionality to `Stringer`. Thx all who asked for it!* | ||
- 1.3.3 *Bugfix: very large/infinite streams with garbage didn't fail. Thx [Arne Marschall](https://github.com/Disco1267)!* | ||
@@ -115,0 +116,0 @@ - 1.3.2 *Bugfix: filters could fail with packed-only token streams. Thx [Trey Brisbane](https://github.com/treybrisbane)!* |
@@ -39,2 +39,4 @@ 'use strict'; | ||
const doNothing = () => {}; | ||
class Stringer extends Transform { | ||
@@ -54,2 +56,3 @@ static make(options) { | ||
'useNumberValues' in options && (this._values.numberValue = options.useNumberValues); | ||
this._makeArray = options.makeArray; | ||
} | ||
@@ -59,4 +62,20 @@ | ||
this._depth = 0; | ||
if (this._makeArray) { | ||
this._transform = this._arrayTransform; | ||
this._flush = this._arrayFlush; | ||
} | ||
} | ||
_arrayTransform(chunk, encoding, callback) { | ||
// it runs once | ||
delete this._transform; | ||
this._transform({name: 'startArray'}, encoding, doNothing); | ||
this._transform(chunk, encoding, callback); | ||
} | ||
_arrayFlush(callback) { | ||
this._transform({name: 'endArray'}, null, callback); | ||
} | ||
_transform(chunk, _, callback) { | ||
@@ -63,0 +82,0 @@ if (this._values[chunk.name]) { |
@@ -136,2 +136,36 @@ 'use strict'; | ||
}, | ||
function test_stringer_json_stream_objects_as_array(t) { | ||
const async = t.startAsync('test_stringer_json_stream_objects_as_array'); | ||
const parser = makeParser({jsonStreaming: true}), | ||
stringer = new Stringer({makeArray: true}), | ||
pattern = { | ||
a: [[[]]], | ||
b: {a: 1}, | ||
c: {a: 1, b: 2}, | ||
d: [true, 1, "'x\"y'", null, false, true, {}, [], ''], | ||
e: 1, | ||
f: '', | ||
g: true, | ||
h: false, | ||
i: null, | ||
j: [], | ||
k: {} | ||
}; | ||
let string = JSON.stringify(pattern), | ||
shouldBe = '[' + string + ',' + string + ']', | ||
buffer = ''; | ||
string += string; | ||
parser.pipe(stringer); | ||
stringer.on('data', data => (buffer += data)); | ||
stringer.on('end', () => { | ||
eval(t.TEST('shouldBe === buffer')); | ||
async.done(); | ||
}); | ||
new ReadString(string).pipe(parser); | ||
}, | ||
function test_stringer_json_stream_primitives(t) { | ||
@@ -138,0 +172,0 @@ const async = t.startAsync('test_stringer_json_stream_primitives'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
213081
0.68%4341
1%159
0.63%242
0.41%