stream-json
Advanced tools
Comparing version 0.0.5 to 0.1.0
{ | ||
"name": "stream-json", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "stream-json is a collection of node.js 0.10 stream components for creating custom standard-compliant JSON processors, which requires a minimal memory footprint. It can parse JSON files far exceeding available memory. Even individual data items are streamed piece-wise. Streaming SAX-inspired event-based API is included as well.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/uhop/stream-json", |
@@ -69,2 +69,4 @@ # stream-json [](http://travis-ci.org/uhop/stream-json) | ||
If you want to catch parsing errors, attach an error listener directly to a parser component — unlike data errors do not travel through stream pipes. | ||
### Streamer | ||
@@ -71,0 +73,0 @@ |
@@ -5,2 +5,15 @@ var util = require("util"); | ||
// utilities | ||
// long hexadecimal codes: \uXXXX | ||
function fromHex(s){ | ||
return String.fromCharCode(parseInt(s.slice(2), 16)); | ||
} | ||
// short codes: \b \f \n \r \t \" \\ \/ | ||
var codes = {b: "\b", f: "\f", n: "\n", r: "\r", t: "\t", '"': '"', "\\": "\\", "/": "/"}; | ||
// Streamer | ||
function Streamer(options){ | ||
@@ -80,5 +93,8 @@ Transform.call(this, options); | ||
case "plainChunk": // string fragments | ||
case "escapedChunk": | ||
this.push({name: "stringChunk", value: chunk.value}); | ||
break; | ||
case "escapedChars": | ||
this.push({name: "stringChunk", value: | ||
chunk.value.length == 2 ? codes[chunk.value.charAt(1)] : fromHex(chunk.value)}); | ||
break; | ||
default: // white space, punctuations | ||
@@ -85,0 +101,0 @@ if(this._state === "number"){ |
195157
27
742
354