Skip to content
Browse files

Initial commit

  • Loading branch information...
1 parent 00940d7 commit 13b4e93cd9d7bd905dcb0d577ea58557e81063bd @AvnerCohen committed Oct 8, 2012
Showing with 21,637 additions and 25 deletions.
  1. +48 −0 benchmark.rb
  2. +15,689 −1 file.json
  3. +0 −21 javascript/js_benchmark.js
  4. +2 −0 js_JSONStream/node_modules/JSONStream/.npmignore
  5. +4 −0 js_JSONStream/node_modules/JSONStream/.travis.yml
  6. +15 −0 js_JSONStream/node_modules/JSONStream/LICENSE.APACHE2
  7. +24 −0 js_JSONStream/node_modules/JSONStream/LICENSE.MIT
  8. +13 −0 js_JSONStream/node_modules/JSONStream/examples/all_docs.js
  9. +189 −0 js_JSONStream/node_modules/JSONStream/index.js
  10. +24 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/LICENSE
  11. +11 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/README.markdown
  12. +26 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/bench.js
  13. +30 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/examples/twitterfeed.js
  14. +415 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js
  15. +29 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/package.json
  16. +167 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/samplejson/basic.json
  17. +180 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/samplejson/basic2.json
  18. +69 −0 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/test.js
  19. +35 −0 js_JSONStream/node_modules/JSONStream/package.json
  20. +145 −0 js_JSONStream/node_modules/JSONStream/readme.markdown
  21. +41 −0 js_JSONStream/node_modules/JSONStream/test/bool.js
  22. +22 −0 js_JSONStream/node_modules/JSONStream/test/destroy_missing.js
  23. +44 −0 js_JSONStream/node_modules/JSONStream/test/empty.js
  24. +4,030 −0 js_JSONStream/node_modules/JSONStream/test/fixtures/all_npm.json
  25. +39 −0 js_JSONStream/node_modules/JSONStream/test/fn.js
  26. +42 −0 js_JSONStream/node_modules/JSONStream/test/multiple_objects.js
  27. +35 −0 js_JSONStream/node_modules/JSONStream/test/multiple_objects_error.js
  28. +28 −0 js_JSONStream/node_modules/JSONStream/test/parsejson.js
  29. +41 −0 js_JSONStream/node_modules/JSONStream/test/stringify.js
  30. +47 −0 js_JSONStream/node_modules/JSONStream/test/stringify_object.js
  31. +35 −0 js_JSONStream/node_modules/JSONStream/test/test.js
  32. +29 −0 js_JSONStream/node_modules/JSONStream/test/test2.js
  33. +41 −0 js_JSONStream/node_modules/JSONStream/test/two-ways.js
  34. +3 −3 {javascript → js_JSONStream}/package.json
  35. +32 −0 js_JSONStream/run.js
  36. +13 −0 readme.md
View
48 benchmark.rb
@@ -0,0 +1,48 @@
+
+@json_file = "./file.json"
+@cycles = 10
+
+@list_of_folders = Dir.glob('*').select {|f| File.directory? f}
+
+@global_totals = Hash.new
+
+
+puts "About to run benchmarks for all folders inspected."
+
+def run_single_benchmark(full_path_to_executable)
+ command=full_path_to_executable + " " +@json_file
+ total=`#{command}`
+ total.gsub(/\D/, "")
+end
+
+
+def run
+ @cycles.times{ @list_of_folders.each do |folder|
+ file_to_execute =Dir.glob("./#{folder}/*").select{|f| File.executable? f and !File.directory? f}.first
+ total=run_single_benchmark file_to_execute
+
+ if !@global_totals[folder]
+ @global_totals[folder] =0
+ end
+
+ @global_totals[folder]+=total.to_i
+
+ end
+
+ }
+ print_totals
+
+
+end
+
+
+def print_totals
+@global_totals.each{|key, value|
+ puts "For [#{key}] total is:" + (value/@cycles).to_s
+ }
+end
+
+
+
+run
+
View
15,690 file.json
15,689 additions, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
21 javascript/js_benchmark.js
@@ -1,21 +0,0 @@
-var fs = require('fs');
-var JSONStream = require('JSONStream');
-var stream = JSONStream.parse(['rows', true, 'doc']);
-
-var totalRows = 0;
-
-stream.on("start", function(){
- totalRows = 0;
-});
-
-stream.on("data", function(){
- totalRows++;
-});
-
-streams.on("end", function(){
- console.log("Done Parsing ", totalRows, " Rows. Yahoo!");
-});
-
-var fileStream = fs.createReadStream("../file.json");
-
-fileStream.pipe(stream);
View
2 js_JSONStream/node_modules/JSONStream/.npmignore
@@ -0,0 +1,2 @@
+node_modules/*
+node_modules
View
4 js_JSONStream/node_modules/JSONStream/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.8
+
View
15 js_JSONStream/node_modules/JSONStream/LICENSE.APACHE2
@@ -0,0 +1,15 @@
+Apache License, Version 2.0
+
+Copyright (c) 2011 Dominic Tarr
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
View
24 js_JSONStream/node_modules/JSONStream/LICENSE.MIT
@@ -0,0 +1,24 @@
+The MIT License
+
+Copyright (c) 2011 Dominic Tarr
+
+Permission is hereby granted, free of charge,
+to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to
+deal in the Software without restriction, including
+without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom
+the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
13 js_JSONStream/node_modules/JSONStream/examples/all_docs.js
@@ -0,0 +1,13 @@
+var request = require('request')
+ , JSONStream = require('JSONStream')
+ , es = require('event-stream')
+
+var parser = JSONStream.parse(['rows', true]) //emit parts that match this path (any element of the rows array)
+ , req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
+ , logger = es.mapSync(function (data) { //create a stream that logs to stderr,
+ console.error(data)
+ return data
+ })
+
+req.pipe(parser)
+parser.pipe(logger)
View
189 js_JSONStream/node_modules/JSONStream/index.js
@@ -0,0 +1,189 @@
+var Parser = require('jsonparse')
+ , Stream = require('stream').Stream
+
+/*
+
+ the value of this.stack that creationix's jsonparse has is weird.
+
+ it makes this code ugly, but his problem is way harder that mine,
+ so i'll forgive him.
+
+*/
+
+exports.parse = function (path) {
+
+ var stream = new Stream()
+ var parser = new Parser()
+ var count = 0
+ if(!path || !path.length)
+ path = null
+ parser.onValue = function () {
+ if(!this.root && this.stack.length == 1){
+ stream.root = this.value
+ }
+ if(!path || this.stack.length !== path.length)
+ return
+ var _path = []
+ for( var i = 0; i < (path.length - 1); i++) {
+ var key = path[i]
+ var c = this.stack[1 + (+i)]
+
+ if(!c) {
+ return
+ }
+ var m = check(key, c.key)
+ _path.push(c.key)
+
+ if(!m)
+ return
+
+ }
+ var c = this
+
+ var key = path[path.length - 1]
+ var m = check(key, c.key)
+ if(!m)
+ return
+ _path.push(c.key)
+
+ count ++
+ stream.emit('data', this.value[this.key])
+ }
+
+ parser._onToken = parser.onToken;
+
+ parser.onToken = function (token, value) {
+ parser._onToken(token, value);
+ if (this.stack.length === 0) {
+ if (stream.root) {
+ if(!path)
+ stream.emit('data', stream.root)
+ stream.emit('root', stream.root, count)
+ count = 0;
+ stream.root = null;
+ }
+ }
+ }
+
+ parser.onError = function (err) {
+ stream.emit('error', err)
+ }
+ stream.readable = true
+ stream.writable = true
+ stream.write = function (chunk) {
+ if('string' === typeof chunk) {
+ if ('undefined' === typeof Buffer) {
+ var buf = new Array(chunk.length)
+ for (var i = 0; i < chunk.length; i++) buf[i] = chunk.charCodeAt(i)
+ chunk = new Int32Array(buf)
+ } else {
+ chunk = new Buffer(chunk)
+ }
+ }
+ parser.write(chunk)
+ }
+ stream.end = function (data) {
+ if(data)
+ stream.write(data)
+ stream.emit('end')
+ }
+
+ stream.destroy = function () {
+ stream.emit('close');
+ }
+
+ return stream
+}
+
+function check (x, y) {
+ if ('string' === typeof x)
+ return y == x
+ else if (x && 'function' === typeof x.exec)
+ return x.exec(y)
+ else if ('boolean' === typeof x)
+ return x
+ else if ('function' === typeof x)
+ return x(y)
+ return false
+}
+
+exports.stringify = function (op, sep, cl) {
+ if (op === false){
+ op = ''
+ sep = '\n'
+ cl = ''
+ } else if (op == null) {
+
+ op = '[\n'
+ sep = '\n,\n'
+ cl = '\n]\n'
+
+ }
+
+ //else, what ever you like
+
+ var stream = new Stream ()
+ , first = true
+ , ended = false
+ , anyData = false
+ stream.write = function (data) {
+ anyData = true
+ var json = JSON.stringify(data)
+ if(first) { first = false ; stream.emit('data', op + json)}
+ else stream.emit('data', sep + json)
+ }
+ stream.end = function (data) {
+ if(ended)
+ return
+ ended = true
+ if(data) stream.write(data)
+ if(!anyData) stream.emit('data', op)
+ stream.emit('data', cl)
+
+ stream.emit('end')
+ }
+ stream.writable = true
+ stream.readable = true
+
+ return stream
+}
+
+exports.stringifyObject = function (op, sep, cl) {
+ if (op === false){
+ op = ''
+ sep = '\n'
+ cl = ''
+ } else if (op == null) {
+
+ op = '{\n'
+ sep = '\n,\n'
+ cl = '\n}\n'
+
+ }
+
+ //else, what ever you like
+
+ var stream = new Stream ()
+ , first = true
+ , ended = false
+ , anyData = false
+ stream.write = function (data) {
+ anyData = true
+ var json = JSON.stringify(data[0]) + ':' + JSON.stringify(data[1])
+ if(first) { first = false ; stream.emit('data', op + json)}
+ else stream.emit('data', sep + json)
+ }
+ stream.end = function (data) {
+ if(ended) return
+ ended = true
+ if(data) stream.write(data)
+ if(!anyData) stream.emit('data', op)
+ stream.emit('data', cl)
+
+ stream.emit('end')
+ }
+ stream.writable = true
+ stream.readable = true
+
+ return stream
+}
View
24 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/LICENSE
@@ -0,0 +1,24 @@
+The MIT License
+
+Copyright (c) 2012 Tim Caswell
+
+Permission is hereby granted, free of charge,
+to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to
+deal in the Software without restriction, including
+without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom
+the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
11 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/README.markdown
@@ -0,0 +1,11 @@
+This is a streaming JSON parser. For a simpler, sax-based version see this gist: https://gist.github.com/1821394
+
+The MIT License (MIT)
+Copyright (c) 2011-2012 Tim Caswell
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
View
26 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/bench.js
@@ -0,0 +1,26 @@
+var fs = require('fs'),
+ Parser = require('./jsonparse');
+
+
+var json = fs.readFileSync("samplejson/basic.json");
+
+
+while (true) {
+ var start = Date.now();
+ for (var i = 0; i < 1000; i++) {
+ JSON.parse(json);
+ }
+ var first = Date.now() - start;
+
+ start = Date.now();
+ var p = new Parser();
+ for (var i = 0; i < 1000; i++) {
+ p.write(json);
+ }
+ var second = Date.now() - start;
+
+
+ console.log("JSON.parse took %s", first);
+ console.log("streaming parser took %s", second);
+ console.log("streaming is %s times slower", second / first);
+}
View
30 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/examples/twitterfeed.js
@@ -0,0 +1,30 @@
+var Parser = require('../jsonparse');
+var Http = require('http');
+require('./colors');
+var p = new Parser();
+var cred = require('./credentials');
+var client = Http.createClient(80, "stream.twitter.com");
+var request = client.request("GET", "/1/statuses/sample.json", {
+ "Host": "stream.twitter.com",
+ "Authorization": (new Buffer(cred.username + ":" + cred.password)).toString("base64")
+});
+request.on('response', function (response) {
+ console.log(response.statusCode);
+ console.dir(response.headers);
+ response.on('data', function (chunk) {
+ p.write(chunk);
+ });
+ response.on('end', function () {
+ console.log("END");
+ });
+});
+request.end();
+var text = "", name = "";
+p.onValue = function (value) {
+ if (this.stack.length === 1 && this.key === 'text') { text = value; }
+ if (this.stack.length === 2 && this.key === 'name' && this.stack[1].key === 'user') { name = value; }
+ if (this.stack.length === 0) {
+ console.log(text.blue + " - " + name.yellow);
+ text = name = "";
+ }
+};
View
415 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js
@@ -0,0 +1,415 @@
+/*global Buffer*/
+// Named constants with unique integer values
+var C = {};
+// Tokens
+var LEFT_BRACE = C.LEFT_BRACE = 0x1;
+var RIGHT_BRACE = C.RIGHT_BRACE = 0x2;
+var LEFT_BRACKET = C.LEFT_BRACKET = 0x3;
+var RIGHT_BRACKET = C.RIGHT_BRACKET = 0x4;
+var COLON = C.COLON = 0x5;
+var COMMA = C.COMMA = 0x6;
+var TRUE = C.TRUE = 0x7;
+var FALSE = C.FALSE = 0x8;
+var NULL = C.NULL = 0x9;
+var STRING = C.STRING = 0xa;
+var NUMBER = C.NUMBER = 0xb;
+// Tokenizer States
+var START = C.START = 0x11;
+var TRUE1 = C.TRUE1 = 0x21;
+var TRUE2 = C.TRUE2 = 0x22;
+var TRUE3 = C.TRUE3 = 0x23;
+var FALSE1 = C.FALSE1 = 0x31;
+var FALSE2 = C.FALSE2 = 0x32;
+var FALSE3 = C.FALSE3 = 0x33;
+var FALSE4 = C.FALSE4 = 0x34;
+var NULL1 = C.NULL1 = 0x41;
+var NULL2 = C.NULL3 = 0x42;
+var NULL3 = C.NULL2 = 0x43;
+var NUMBER1 = C.NUMBER1 = 0x51;
+var NUMBER2 = C.NUMBER2 = 0x52;
+var NUMBER3 = C.NUMBER3 = 0x53;
+var NUMBER4 = C.NUMBER4 = 0x54;
+var NUMBER5 = C.NUMBER5 = 0x55;
+var NUMBER6 = C.NUMBER6 = 0x56;
+var NUMBER7 = C.NUMBER7 = 0x57;
+var NUMBER8 = C.NUMBER8 = 0x58;
+var STRING1 = C.STRING1 = 0x61;
+var STRING2 = C.STRING2 = 0x62;
+var STRING3 = C.STRING3 = 0x63;
+var STRING4 = C.STRING4 = 0x64;
+var STRING5 = C.STRING5 = 0x65;
+var STRING6 = C.STRING6 = 0x66;
+// Parser States
+var VALUE = C.VALUE = 0x71;
+var KEY = C.KEY = 0x72;
+// Parser Modes
+var OBJECT = C.OBJECT = 0x81;
+var ARRAY = C.ARRAY = 0x82;
+
+// Slow code to string converter (only used when throwing syntax errors)
+function toknam(code) {
+ var keys = Object.keys(C);
+ for (var i = 0, l = keys.length; i < l; i++) {
+ var key = keys[i];
+ if (C[key] === code) { return key; }
+ }
+ return code && ("0x" + code.toString(16));
+}
+
+
+function Parser() {
+ this.tState = START;
+ this.value = undefined;
+
+ this.string = undefined; // string data
+ this.unicode = undefined; // unicode escapes
+
+ // For number parsing
+ this.negative = undefined;
+ this.magnatude = undefined;
+ this.position = undefined;
+ this.exponent = undefined;
+ this.negativeExponent = undefined;
+
+ this.key = undefined;
+ this.mode = undefined;
+ this.stack = [];
+ this.state = VALUE;
+}
+var proto = Parser.prototype;
+proto.charError = function (buffer, i) {
+ this.onError(new Error("Unexpected " + JSON.stringify(String.fromCharCode(buffer[i])) + " at position " + i + " in state " + toknam(this.tState)));
+};
+proto.onError = function (err) { throw err; };
+proto.write = function (buffer) {
+ if (typeof buffer === "string") buffer = new Buffer(buffer);
+ //process.stdout.write("Input: ");
+ //console.dir(buffer.toString());
+ var n;
+ for (var i = 0, l = buffer.length; i < l; i++) {
+ switch (this.tState) {
+ case START:
+ n = buffer[i];
+ switch (n) {
+ case 0x7b: this.onToken(LEFT_BRACE, "{"); break; // {
+ case 0x7d: this.onToken(RIGHT_BRACE, "}"); break; // }
+ case 0x5b: this.onToken(LEFT_BRACKET, "["); break; // [
+ case 0x5d: this.onToken(RIGHT_BRACKET, "]"); break; // ]
+ case 0x3a: this.onToken(COLON, ":"); break; // :
+ case 0x2c: this.onToken(COMMA, ","); break; // ,
+ case 0x74: this.tState = TRUE1; break; // t
+ case 0x66: this.tState = FALSE1; break; // f
+ case 0x6e: this.tState = NULL1; break; // n
+ case 0x22: this.string = ""; this.tState = STRING1; break; // "
+ case 0x2d: this.negative = true; this.tState = NUMBER1; break; // -
+ case 0x30: this.magnatude = 0; this.tState = NUMBER2; break; // 0
+ default:
+ if (n > 0x30 && n < 0x40) { // 1-9
+ this.magnatude = n - 0x30; this.tState = NUMBER3;
+ } else if (n === 0x20 || n === 0x09 || n === 0x0a || n === 0x0d) {
+ // whitespace
+ } else { this.charError(buffer, i); }
+ break;
+ }
+ break;
+ case STRING1: // After open quote
+ n = buffer[i];
+ // TODO: Handle native utf8 characters, this code assumes ASCII input
+ if (n === 0x22) { this.tState = START; this.onToken(STRING, this.string); this.string = undefined; }
+ else if (n === 0x5c) { this.tState = STRING2; }
+ else if (n >= 0x20) { this.string += String.fromCharCode(n); }
+ else { this.charError(buffer, i); }
+ break;
+ case STRING2: // After backslash
+ n = buffer[i];
+ switch (n) {
+ case 0x22: this.string += "\""; this.tState = STRING1; break;
+ case 0x5c: this.string += "\\"; this.tState = STRING1; break;
+ case 0x2f: this.string += "\/"; this.tState = STRING1; break;
+ case 0x62: this.string += "\b"; this.tState = STRING1; break;
+ case 0x66: this.string += "\f"; this.tState = STRING1; break;
+ case 0x6e: this.string += "\n"; this.tState = STRING1; break;
+ case 0x72: this.string += "\r"; this.tState = STRING1; break;
+ case 0x74: this.string += "\t"; this.tState = STRING1; break;
+ case 0x75: this.unicode = ""; this.tState = STRING3; break;
+ default: this.charError(buffer, i); break;
+ }
+ break;
+ case STRING3: case STRING4: case STRING5: case STRING6: // unicode hex codes
+ n = buffer[i];
+ // 0-9 A-F a-f
+ if ((n >= 0x30 && n < 0x40) || (n > 0x40 && n <= 0x46) || (n > 0x60 && n <= 0x66)) {
+ this.unicode += String.fromCharCode(n);
+ if (this.tState++ === STRING6) {
+ this.string += String.fromCharCode(parseInt(this.unicode, 16));
+ this.unicode = undefined;
+ this.tState = STRING1;
+ }
+ } else {
+ this.charError(buffer, i);
+ }
+ break;
+ case NUMBER1: // after minus
+ n = buffer[i];
+ if (n === 0x30) { this.magnatude = 0; this.tState = NUMBER2; }
+ else if (n > 0x30 && n < 0x40) { this.magnatude = n - 0x30; this.tState = NUMBER3; }
+ else { this.charError(buffer, i); }
+ break;
+ case NUMBER2: // * After initial zero
+ switch (buffer[i]) {
+ case 0x2e: // .
+ this.position = 0.1; this.tState = NUMBER4; break;
+ case 0x65: case 0x45: // e/E
+ this.exponent = 0; this.tState = NUMBER6; break;
+ default:
+ this.tState = START;
+ this.onToken(NUMBER, 0);
+ this.magnatude = undefined;
+ this.negative = undefined;
+ i--;
+ break;
+ }
+ break;
+ case NUMBER3: // * After digit (before period)
+ n = buffer[i];
+ switch (n) {
+ case 0x2e: // .
+ this.position = 0.1; this.tState = NUMBER4; break;
+ case 0x65: case 0x45: // e/E
+ this.exponent = 0; this.tState = NUMBER6; break;
+ default:
+ if (n >= 0x30 && n < 0x40) { this.magnatude = this.magnatude * 10 + n - 0x30; }
+ else {
+ this.tState = START;
+ if (this.negative) {
+ this.magnatude = -this.magnatude;
+ this.negative = undefined;
+ }
+ this.onToken(NUMBER, this.magnatude);
+ this.magnatude = undefined;
+ i--;
+ }
+ break;
+ }
+ break;
+ case NUMBER4: // After period
+ n = buffer[i];
+ if (n >= 0x30 && n < 0x40) { // 0-9
+ this.magnatude += this.position * (n - 0x30);
+ this.position /= 10;
+ this.tState = NUMBER5;
+ } else { this.charError(buffer, i); }
+ break;
+ case NUMBER5: // * After digit (after period)
+ n = buffer[i];
+ if (n >= 0x30 && n < 0x40) { // 0-9
+ this.magnatude += this.position * (n - 0x30);
+ this.position /= 10;
+ }
+ else if (n === 0x65 || n === 0x45) { this.exponent = 0; this.tState = NUMBER6; } // E/e
+ else {
+ this.tState = START;
+ if (this.negative) {
+ this.magnatude = -this.magnatude;
+ this.negative = undefined;
+ }
+ this.onToken(NUMBER, this.negative ? -this.magnatude : this.magnatude);
+ this.magnatude = undefined;
+ this.position = undefined;
+ i--;
+ }
+ break;
+ case NUMBER6: // After E
+ n = buffer[i];
+ if (n === 0x2b || n === 0x2d) { // +/-
+ if (n === 0x2d) { this.negativeExponent = true; }
+ this.tState = NUMBER7;
+ }
+ else if (n >= 0x30 && n < 0x40) {
+ this.exponent = this.exponent * 10 + (n - 0x30);
+ this.tState = NUMBER8;
+ }
+ else { this.charError(buffer, i); }
+ break;
+ case NUMBER7: // After +/-
+ n = buffer[i];
+ if (n >= 0x30 && n < 0x40) { // 0-9
+ this.exponent = this.exponent * 10 + (n - 0x30);
+ this.tState = NUMBER8;
+ }
+ else { this.charError(buffer, i); }
+ break;
+ case NUMBER8: // * After digit (after +/-)
+ n = buffer[i];
+ if (n >= 0x30 && n < 0x40) { // 0-9
+ this.exponent = this.exponent * 10 + (n - 0x30);
+ }
+ else {
+ if (this.negativeExponent) {
+ this.exponent = -this.exponent;
+ this.negativeExponent = undefined;
+ }
+ this.magnatude *= Math.pow(10, this.exponent);
+ this.exponent = undefined;
+ if (this.negative) {
+ this.magnatude = -this.magnatude;
+ this.negative = undefined;
+ }
+ this.tState = START;
+ this.onToken(NUMBER, this.magnatude);
+ this.magnatude = undefined;
+ i--;
+ }
+ break;
+ case TRUE1: // r
+ if (buffer[i] === 0x72) { this.tState = TRUE2; }
+ else { this.charError(buffer, i); }
+ break;
+ case TRUE2: // u
+ if (buffer[i] === 0x75) { this.tState = TRUE3; }
+ else { this.charError(buffer, i); }
+ break;
+ case TRUE3: // e
+ if (buffer[i] === 0x65) { this.tState = START; this.onToken(TRUE, true); }
+ else { this.charError(buffer, i); }
+ break;
+ case FALSE1: // a
+ if (buffer[i] === 0x61) { this.tState = FALSE2; }
+ else { this.charError(buffer, i); }
+ break;
+ case FALSE2: // l
+ if (buffer[i] === 0x6c) { this.tState = FALSE3; }
+ else { this.charError(buffer, i); }
+ break;
+ case FALSE3: // s
+ if (buffer[i] === 0x73) { this.tState = FALSE4; }
+ else { this.charError(buffer, i); }
+ break;
+ case FALSE4: // e
+ if (buffer[i] === 0x65) { this.tState = START; this.onToken(FALSE, false); }
+ else { this.charError(buffer, i); }
+ break;
+ case NULL1: // u
+ if (buffer[i] === 0x75) { this.tState = NULL2; }
+ else { this.charError(buffer, i); }
+ break;
+ case NULL2: // l
+ if (buffer[i] === 0x6c) { this.tState = NULL3; }
+ else { this.charError(buffer, i); }
+ break;
+ case NULL3: // l
+ if (buffer[i] === 0x6c) { this.tState = START; this.onToken(NULL, null); }
+ else { this.charError(buffer, i); }
+ break;
+ }
+ }
+};
+proto.onToken = function (token, value) {
+ // Override this to get events
+};
+
+proto.parseError = function (token, value) {
+ this.onError(new Error("Unexpected " + toknam(token) + (value ? ("(" + JSON.stringify(value) + ")") : "") + " in state " + toknam(this.state)));
+};
+proto.onError = function (err) { throw err; };
+proto.push = function () {
+ this.stack.push({value: this.value, key: this.key, mode: this.mode});
+};
+proto.pop = function () {
+ var value = this.value;
+ var parent = this.stack.pop();
+ this.value = parent.value;
+ this.key = parent.key;
+ this.mode = parent.mode;
+ this.emit(value);
+ if (!this.mode) { this.state = VALUE; }
+};
+proto.emit = function (value) {
+ if (this.mode) { this.state = COMMA; }
+ this.onValue(value);
+};
+proto.onValue = function (value) {
+ // Override me
+};
+proto.onToken = function (token, value) {
+ //console.log("OnToken: state=%s token=%s %s", toknam(this.state), toknam(token), value?JSON.stringify(value):"");
+ switch (this.state) {
+ case VALUE:
+ switch (token) {
+ case STRING: case NUMBER: case TRUE: case FALSE: case NULL:
+ if (this.value) {
+ this.value[this.key] = value;
+ }
+ this.emit(value);
+ break;
+ case LEFT_BRACE:
+ this.push();
+ if (this.value) {
+ this.value = this.value[this.key] = {};
+ } else {
+ this.value = {};
+ }
+ this.key = undefined;
+ this.state = KEY;
+ this.mode = OBJECT;
+ break;
+ case LEFT_BRACKET:
+ this.push();
+ if (this.value) {
+ this.value = this.value[this.key] = [];
+ } else {
+ this.value = [];
+ }
+ this.key = 0;
+ this.mode = ARRAY;
+ this.state = VALUE;
+ break;
+ case RIGHT_BRACE:
+ if (this.mode === OBJECT) {
+ this.pop();
+ } else {
+ this.parseError(token, value);
+ }
+ break;
+ case RIGHT_BRACKET:
+ if (this.mode === ARRAY) {
+ this.pop();
+ } else {
+ this.parseError(token, value);
+ }
+ break;
+ default:
+ this.parseError(token, value); break;
+ }
+ break;
+ case KEY:
+ if (token === STRING) {
+ this.key = value;
+ this.state = COLON;
+ } else if (token === RIGHT_BRACE) {
+ this.pop();
+ } else {
+ this.parseError(token, value);
+ }
+ break;
+ case COLON:
+ if (token === COLON) { this.state = VALUE; }
+ else { this.parseError(token, value); }
+ break;
+ case COMMA:
+ if (token === COMMA) {
+ if (this.mode === ARRAY) { this.key++; this.state = VALUE; }
+ else if (this.mode === OBJECT) { this.state = KEY; }
+
+ } else if (token === RIGHT_BRACKET && this.mode === ARRAY || token === RIGHT_BRACE && this.mode === OBJECT) {
+ this.pop();
+ } else {
+ this.parseError(token, value);
+ }
+ break;
+ default:
+ this.parseError(token, value);
+ }
+};
+
+module.exports = Parser;
View
29 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "jsonparse",
+ "description": "This is a pure-js JSON streaming parser for node.js",
+ "tags": [
+ "json",
+ "stream"
+ ],
+ "version": "0.0.2",
+ "author": {
+ "name": "Tim Caswell",
+ "email": "tim@creationix.com"
+ },
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/creationix/jsonparse.git"
+ },
+ "bugs": "http://github.com/creationix/jsonparse/issues",
+ "engines": [
+ "node >= 0.2.0"
+ ],
+ "license": "MIT",
+ "main": "jsonparse.js",
+ "readme": "This is a streaming JSON parser. For a simpler, sax-based version see this gist: https://gist.github.com/1821394\n\nThe MIT License (MIT)\nCopyright (c) 2011-2012 Tim Caswell\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n",
+ "_id": "jsonparse@0.0.2",
+ "dist": {
+ "shasum": "ece083f0b2be2117cf274ce8db85cbe6045e526a"
+ },
+ "_from": "jsonparse@0.0.2"
+}
View
167 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/samplejson/basic.json
@@ -0,0 +1,167 @@
+[
+ {
+ },
+ {
+ "image": [
+ {"shape": "rect", "fill": "#333", "stroke": "#999", "x": 0.5e+1, "y": 0.5, "z": 0.8e-0, "w": 0.5e5, "u": 2E10, "foo": 2E+1, "bar": 2E-0, "width": 47, "height": 47}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#248", "stroke": "#48f", "points": [[0.5,47.5],[47.5,47.5],[47.5,0.5]]}
+ ],
+ "solid": {
+ "1": [2,4],
+ "2": [1],
+ "3": [2],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": false,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#248", "stroke": "#48f", "points": [[0.5,0.5],[47.5,47.5],[0.5,47.5]]}
+ ],
+ "solid": {
+ "1": [2],
+ "2": [3],
+ "3": [2,6],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": true,"9": false}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#333", "stroke": "#999", "points": [[0.5,0.5],[47.5,47.5],[47.5,0.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [3],
+ "7": [4,8],
+ "8": [7],
+ "9": [6,8]
+ },
+ "corners": {"1": false,"3": true,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#333", "stroke": "#999", "points": [[0.5,0.5],[0.5,47.5],[47.5,0.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [1],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [9],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": false,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#482", "stroke": "#8f4", "points": [[0.5,47.5],[0.5,23.5],[24.5,23.5],[24.5,0.5],[47.5,0.5],[47.5,47.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [6,2],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [9],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": false,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#482", "stroke": "#8f4", "points": [[0.5,0.5],[23.5,0.5],[23.5,24.5],[47.5,24.5],[47.5,47.5],[0.5,47.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [4,2],
+ "2": [],
+ "3": [2,6],
+ "4": [7],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": true,"9": false}
+ },
+ {
+ "image": [
+ {"shape": "circle", "fill": "#ff0", "stroke": "#ff8", "cx": 24, "cy": 24, "r": 18}
+ ],
+ "item": true
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#842", "stroke": "#f84", "points": [[4.5,0.5],[14.5,0.5],[14.5,17.5],[34,17.5],[33.5,0.5],[43.5,0.5],[43.5,47.5],[33.5,47.5],[33.5,30.5],[14.5,30.5],[14.5,47.5],[4.5,47.5]]}
+ ],
+ "jumpable": 3
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#333", "stroke": "#999", "points": [[0.5,0.5],[47.5,0.5],[24,47.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [1],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [3],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": false,"3": false,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "rect", "fill": "#114acb", "x": 0.5, "y": 0.5, "width": 47, "height": 47},
+ {"shape": "polygon", "fill": "rgba(255,255,255,0.30)", "points": [[0.5,0.5],[47.5,0.5],[40,8],[8,8],[8,40],[0.5,47.5]]},
+ {"shape": "polygon", "fill": "rgba(0,0,0,0.30)", "points": [[47.5,0.5],[48,48],[0.5,47.5],[8,40],[40,40],[40,8]]},
+ {"shape": "polygon", "fill": "rgb(255,255,0)", "stroke": "rgba(255,255,0,0.5)", "points": [[24,9],[35,20],[26,29],[26,33],[22,33],[22,27],[29,20],[24,15],[16,23],[13,20]]},
+ {"shape": "rect", "fill": "rgb(255,255,0)", "stroke": "rgba(255,255,0,0.5)", "x": 22, "y":35, "width": 4, "height": 4}
+ ]
+ }
+]
View
180 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/samplejson/basic2.json
@@ -0,0 +1,180 @@
+[
+ {
+ },
+ {
+ "image": [
+ {"shape": "rect", "fill": "#333", "stroke": "#999", "x": 0.5, "y": 0.5, "width": 47, "height": 47}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#248", "stroke": "#48f", "points": [[0.5,47.5],[47.5,47.5],[47.5,0.5]]}
+ ],
+ "solid": {
+ "1": [2,4],
+ "2": [1],
+ "3": [2],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": false,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#248", "stroke": "#48f", "points": [[0.5,0.5],[47.5,47.5],[0.5,47.5]]}
+ ],
+ "solid": {
+ "1": [2],
+ "2": [3],
+ "3": [2,6],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": true,"9": false}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#333", "stroke": "#999", "points": [[0.5,0.5],[47.5,47.5],[47.5,0.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [3],
+ "7": [4,8],
+ "8": [7],
+ "9": [6,8]
+ },
+ "corners": {"1": false,"3": true,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#333", "stroke": "#999", "points": [[0.5,0.5],[0.5,47.5],[47.5,0.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [1],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [9],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": false,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#482", "stroke": "#8f4", "points": [[0.5,47.5],[0.5,23.5],[24.5,23.5],[24.5,0.5],[47.5,0.5],[47.5,47.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [6,2],
+ "4": [],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [9],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": false,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#482", "stroke": "#8f4", "points": [[0.5,0.5],[23.5,0.5],[23.5,24.5],[47.5,24.5],[47.5,47.5],[0.5,47.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [4,2],
+ "2": [],
+ "3": [2,6],
+ "4": [7],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": true,"3": true,"7": true,"9": false}
+ },
+ {
+ "image": [
+ {"shape": "circle", "fill": "#ff0", "stroke": "#ff8", "cx": 24, "cy": 24, "r": 18}
+ ],
+ "item": true
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#842", "stroke": "#f84", "points": [[4.5,0.5],[14.5,0.5],[14.5,17.5],[34,17.5],[33.5,0.5],[43.5,0.5],[43.5,47.5],[33.5,47.5],[33.5,30.5],[14.5,30.5],[14.5,47.5],[4.5,47.5]]}
+ ],
+ "jumpable": 3
+ },
+ {
+ "image": [
+ {"shape": "polygon", "fill": "#333", "stroke": "#999", "points": [[0.5,0.5],[47.5,0.5],[24,47.5]]}
+ ],
+ "jumpable": 3,
+ "solid": {
+ "1": [2,4],
+ "2": [],
+ "3": [2,6],
+ "4": [1],
+ "5": [2,8,1,3,7,9,4,6],
+ "6": [3],
+ "7": [4,8],
+ "8": [],
+ "9": [6,8]
+ },
+ "corners": {"1": false,"3": false,"7": true,"9": true}
+ },
+ {
+ "image": [
+ {"shape": "rect", "fill": "#114acb", "x": 0.5, "y": 0.5, "width": 47, "height": 47},
+ {"shape": "polygon", "fill": "rgba(255,255,255,0.30)", "points": [[0.5,0.5],[47.5,0.5],[40,8],[8,8],[8,40],[0.5,47.5]]},
+ {"shape": "polygon", "fill": "rgba(0,0,0,0.30)", "points": [[47.5,0.5],[48,48],[0.5,47.5],[8,40],[40,40],[40,8]]},
+ {"shape": "polygon", "fill": "rgb(255,255,0)", "stroke": "rgba(255,255,0,0.5)", "points": [[24,9],[35,20],[26,29],[26,33],[22,33],[22,27],[29,20],[24,15],[16,23],[13,20]]},
+ {"shape": "rect", "fill": "rgb(255,255,0)", "stroke": "rgba(255,255,0,0.5)", "x": 22, "y":35, "width": 4, "height": 4}
+ ],
+ "item": true
+ },
+ {
+ "image": [
+ {"shape": "circle", "fill": "#80f", "stroke": "#88f", "cx": 24, "cy": 24, "r": 18}
+ ],
+ "item": true
+ },
+ {
+ "image": [
+ {"shape": "circle", "fill": "#4f4", "stroke": "#8f8", "cx": 24, "cy": 24, "r": 18}
+ ],
+ "item": true
+ }
+]
View
69 js_JSONStream/node_modules/JSONStream/node_modules/jsonparse/test.js
@@ -0,0 +1,69 @@
+/*global Buffer*/
+var Parser = require('./jsonparse');
+var fs = require('fs');
+/*
+var t = new Tokenizer();
+t.onToken = function (token, value) {
+ console.log("%s %s", token, value);
+}
+t.write(new Buffer("123false1.3true{}[]"));
+t.write(new Buffer("truefalsenullnulltruefalse"));
+t.write(new Buffer("tru"));
+t.write(new Buffer("efa"));
+t.write(new Buffer("lse"));
+t.write(new Buffer(JSON.stringify({"Hello":"World"})));
+*/
+// Make sure it's parsing correctly before any benchmarking is done
+var json = fs.readFileSync("samplejson/basic.json");
+var t = new Parser();
+var v;
+t.onValue = function (value) { v = value; };
+t.write(json);
+if (JSON.stringify(v) !== JSON.stringify(JSON.parse(json))) {
+ throw new Error("Invalid parse result:\n" + JSON.stringify(v));
+}
+var p = new Parser();
+p.onValue = function (value) {
+ var keys = this.stack.map(function (item) {
+ return '.' + item.key;
+ }, this);
+ keys.push('.' + this.key);
+ keys.shift();
+ var o = JSON.stringify(value) || "";
+ if (o.length > 80) {
+ o = o.substr(0, 77) + "...";
+ }
+ console.log("value%s = %s", keys.join(''), o);
+};
+//p.write(JSON.stringify([1,2,3]));
+//p.write(JSON.stringify([]));
+//p.write(JSON.stringify([[]]));
+p.write('"""Hello""This\\"is""\\r\\n\\f\\t\\\\\\/\\""');
+p.write('"\\u039b\\u03ac\\u03bc\\u03b2\\u03b4\\u03b1"');
+p.write('"\\\\"');
+p.write('"\\/"');
+p.write('"\\""');
+p.write('[0,1,-1]');
+p.write('[1.0,1.1,-1.1,-1.0][-1][-0.1]');
+p.write('[6.02e23]');
+// p.write('{"name": "Tim", "age": 28}');
+// p.write('{}');
+//p.write('[{"name":null}]');
+//p.write('[{}]');
+//p.write('[{},[],{}]');
+//p.write('{"a":[],"b":{}}');
+//require('fs').readFile('samplejson/basic.json', function (err, buffer) {
+// if (err) { throw err; }
+// p.write(buffer);
+//});
+/*
+p.write(new Buffer("123false1.3true{}[]"));
+p.write(new Buffer('{ "name": "Tim", "age": 28 }'));
+p.write(new Buffer('{\n\t"name": "Tim",\n\t"age": 28\n}'));
+p.write(new Buffer('{\r\n\t"name": "Tim",\r\n\t"age": 28\r\n}'));
+p.write(new Buffer("truefalsenullnulltruefalse"));
+p.write(new Buffer("tru"));
+p.write(new Buffer("efa"));
+p.write(new Buffer("lse"));
+p.write(new Buffer(JSON.stringify({"Hello":"World"})));
+*/
View
35 js_JSONStream/node_modules/JSONStream/package.json
@@ -0,0 +1,35 @@
+{
+ "name": "JSONStream",
+ "version": "0.4.2",
+ "description": "rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)",
+ "homepage": "http://github.com/dominictarr/JSONStream",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/dominictarr/JSONStream.git"
+ },
+ "dependencies": {
+ "jsonparse": "0.0.2"
+ },
+ "devDependencies": {
+ "it-is": "~1",
+ "assertions": "~2.2.2",
+ "render": "~0.1.1",
+ "trees": "~0.0.3",
+ "event-stream": "~0.7.0"
+ },
+ "author": {
+ "name": "Dominic Tarr",
+ "email": "dominic.tarr@gmail.com",
+ "url": "http://bit.ly/dominictarr"
+ },
+ "scripts": {
+ "test": "set -e; for t in test/*.js; do echo '***' $t '***'; node $t; done"
+ },
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ },
+ "readme": "# JSONStream\n\nstreaming JSON.parse and stringify\n\n<img src=https://secure.travis-ci.org/dominictarr/JSONStream.png?branch=master>\n\n## example\n\n```javascript\n\nvar request = require('request')\n , JSONStream = require('JSONStream')\n , es = require('event-stream')\n\nvar parser = JSONStream.parse(['rows', true])\n , req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'})\n , logger = es.mapSync(function (data) {\n console.error(data)\n return data\n })\n```\n\nin node 0.4.x\n\n``` javascript\n\nreq.pipe(parser)\nparser.pipe(logger)\n\n```\n\nin node v0.5.x\n\n``` javascript\nreq.pipe(parser).pipe(logger)\n\n```\n\n## JSONStream.parse(path)\n\nusally, a json API will return a list of objects.\n\n`path` should be an array of property names, `RegExp`s, booleans, and/or functions.\nany object that matches the path will be emitted as 'data' (and `pipe`d down stream)\n\na 'root' event is emitted when all data has been received. The 'root' event passes the root object & the count of matched objects.\n\nif `path` is empty or null, no 'data' events are emitted.\n\n### example\n\nquery a couchdb view:\n\n``` bash\ncurl -sS localhost:5984/tests/_all_docs&include_docs=true\n```\nyou will get something like this:\n\n``` js\n{\"total_rows\":129,\"offset\":0,\"rows\":[\n { \"id\":\"change1_0.6995461115147918\"\n , \"key\":\"change1_0.6995461115147918\"\n , \"value\":{\"rev\":\"1-e240bae28c7bb3667f02760f6398d508\"}\n , \"doc\":{\n \"_id\": \"change1_0.6995461115147918\"\n , \"_rev\": \"1-e240bae28c7bb3667f02760f6398d508\",\"hello\":1}\n },\n { \"id\":\"change2_0.6995461115147918\"\n , \"key\":\"change2_0.6995461115147918\"\n , \"value\":{\"rev\":\"1-13677d36b98c0c075145bb8975105153\"}\n , \"doc\":{\n \"_id\":\"change2_0.6995461115147918\"\n , \"_rev\":\"1-13677d36b98c0c075145bb8975105153\"\n , \"hello\":2\n }\n },\n]}\n\n```\n\nwe are probably most interested in the `rows.*.docs`\n\ncreate a `Stream` that parses the documents from the feed like this:\n\n``` js\nvar stream = JSONStream.parse(['rows', true, 'doc']) //rows, ANYTHING, doc\n\nstream.on('data', function(data) {\n console.log('received:', data);\n});\n\nstream.on('root', function(root, count) {\n if (!count) {\n console.log('no matches found:', root);\n }\n});\n```\nawesome!\n\n## JSONStream.stringify(open, sep, close)\n\nCreate a writable stream.\n\nyou may pass in custom `open`, `close`, and `seperator` strings.\nBut, by default, `JSONStream.stringify()` will create an array,\n(with default options `open='[\\n', sep='\\n,\\n', close='\\n]\\n'`)\n\nIf you call `JSONStream.stringify(false)`\nthe elements will only be seperated by a newline.\n\nIf you only write one item this will be valid JSON.\n\nIf you write many items,\nyou can use a `RegExp` to split it into valid chunks.\n\n## JSONStream.stringifyObject(open, sep, close)\n\nVery much like `JSONStream.stringify`,\nbut creates a writable stream for objects instead of arrays.\n\nAccordingly, `open='{\\n', sep='\\n,\\n', close='\\n}\\n'`.\n\nWhen you `.write()` to the stream you must supply an array with `[ key, data ]`\nas the first argument.\n\n## numbers\n\nThere are occasional problems parsing and unparsing very precise numbers.\n\nI have opened an issue here:\n\nhttps://github.com/creationix/jsonparse/issues/2\n\n+1\n\n## Acknowlegements\n\nthis module depends on https://github.com/creationix/jsonparse\nby Tim Caswell\nand also thanks to Florent Jaby for teaching me about parsing with:\nhttps://github.com/Floby/node-json-streams\n\n## license\n\nMIT / APACHE2\n",
+ "_id": "JSONStream@0.4.2",
+ "_from": "JSONStream@"
+}
View
145 js_JSONStream/node_modules/JSONStream/readme.markdown
@@ -0,0 +1,145 @@
+# JSONStream
+
+streaming JSON.parse and stringify
+
+<img src=https://secure.travis-ci.org/dominictarr/JSONStream.png?branch=master>
+
+## example
+
+```javascript
+
+var request = require('request')
+ , JSONStream = require('JSONStream')
+ , es = require('event-stream')
+
+var parser = JSONStream.parse(['rows', true])
+ , req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
+ , logger = es.mapSync(function (data) {
+ console.error(data)
+ return data
+ })
+```
+
+in node 0.4.x
+
+``` javascript
+
+req.pipe(parser)
+parser.pipe(logger)
+
+```
+
+in node v0.5.x
+
+``` javascript
+req.pipe(parser).pipe(logger)
+
+```
+
+## JSONStream.parse(path)
+
+usally, a json API will return a list of objects.
+
+`path` should be an array of property names, `RegExp`s, booleans, and/or functions.
+any object that matches the path will be emitted as 'data' (and `pipe`d down stream)
+
+a 'root' event is emitted when all data has been received. The 'root' event passes the root object & the count of matched objects.
+
+if `path` is empty or null, no 'data' events are emitted.
+
+### example
+
+query a couchdb view:
+
+``` bash
+curl -sS localhost:5984/tests/_all_docs&include_docs=true
+```
+you will get something like this:
+
+``` js
+{"total_rows":129,"offset":0,"rows":[
+ { "id":"change1_0.6995461115147918"
+ , "key":"change1_0.6995461115147918"
+ , "value":{"rev":"1-e240bae28c7bb3667f02760f6398d508"}
+ , "doc":{
+ "_id": "change1_0.6995461115147918"
+ , "_rev": "1-e240bae28c7bb3667f02760f6398d508","hello":1}
+ },
+ { "id":"change2_0.6995461115147918"
+ , "key":"change2_0.6995461115147918"
+ , "value":{"rev":"1-13677d36b98c0c075145bb8975105153"}
+ , "doc":{
+ "_id":"change2_0.6995461115147918"
+ , "_rev":"1-13677d36b98c0c075145bb8975105153"
+ , "hello":2
+ }
+ },
+]}
+
+```
+
+we are probably most interested in the `rows.*.docs`
+
+create a `Stream` that parses the documents from the feed like this:
+
+``` js
+var stream = JSONStream.parse(['rows', true, 'doc']) //rows, ANYTHING, doc
+
+stream.on('data', function(data) {
+ console.log('received:', data);
+});
+
+stream.on('root', function(root, count) {
+ if (!count) {
+ console.log('no matches found:', root);
+ }
+});
+```
+awesome!
+
+## JSONStream.stringify(open, sep, close)
+
+Create a writable stream.
+
+you may pass in custom `open`, `close`, and `seperator` strings.
+But, by default, `JSONStream.stringify()` will create an array,
+(with default options `open='[\n', sep='\n,\n', close='\n]\n'`)
+
+If you call `JSONStream.stringify(false)`
+the elements will only be seperated by a newline.
+
+If you only write one item this will be valid JSON.
+
+If you write many items,
+you can use a `RegExp` to split it into valid chunks.
+
+## JSONStream.stringifyObject(open, sep, close)
+
+Very much like `JSONStream.stringify`,
+but creates a writable stream for objects instead of arrays.
+
+Accordingly, `open='{\n', sep='\n,\n', close='\n}\n'`.
+
+When you `.write()` to the stream you must supply an array with `[ key, data ]`
+as the first argument.
+
+## numbers
+
+There are occasional problems parsing and unparsing very precise numbers.
+
+I have opened an issue here:
+
+https://github.com/creationix/jsonparse/issues/2
+
++1
+
+## Acknowlegements
+
+this module depends on https://github.com/creationix/jsonparse
+by Tim Caswell
+and also thanks to Florent Jaby for teaching me about parsing with:
+https://github.com/Floby/node-json-streams
+
+## license
+
+MIT / APACHE2
View
41 js_JSONStream/node_modules/JSONStream/test/bool.js
@@ -0,0 +1,41 @@
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, 'fixtures','all_npm.json')
+ , JSONStream = require('../')
+ , it = require('it-is').style('colour')
+
+ function randomObj () {
+ return (
+ Math.random () < 0.4
+ ? {hello: 'eonuhckmqjk',
+ whatever: 236515,
+ lies: true,
+ nothing: [null],
+// stuff: [Math.random(),Math.random(),Math.random()]
+ }
+ : ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]]
+ )
+ }
+
+var expected = []
+ , stringify = JSONStream.stringify()
+ , es = require('event-stream')
+ , stringified = ''
+ , called = 0
+ , count = 10
+ , ended = false
+
+while (count --)
+ expected.push(randomObj())
+
+ es.connect(
+ es.readArray(expected),
+ stringify,
+ JSONStream.parse([true]),
+ es.writeArray(function (err, lines) {
+
+ it(lines).has(expected)
+ console.error('PASSED')
+ })
+ )
View
22 js_JSONStream/node_modules/JSONStream/test/destroy_missing.js
@@ -0,0 +1,22 @@
+var fs = require ('fs');
+var net = require('net');
+var join = require('path').join;
+var file = join(__dirname, 'fixtures','all_npm.json');
+var JSONStream = require('../');
+
+
+var server = net.createServer(function(client) {
+ var parser = JSONStream.parse([]);
+ parser.on('close', function() {
+ console.error('PASSED');
+ server.close();
+ });
+ client.pipe(parser);
+ client.destroy();
+});
+server.listen(9999);
+
+
+var client = net.connect({ port : 9999 }, function() {
+ fs.createReadStream(file).pipe(client);
+});
View
44 js_JSONStream/node_modules/JSONStream/test/empty.js
@@ -0,0 +1,44 @@
+var JSONStream = require('../')
+ , stream = require('stream')
+ , it = require('it-is')
+
+var output = [ [], [] ]
+
+var parser1 = JSONStream.parse(['docs', /./])
+parser1.on('data', function(data) {
+ output[0].push(data)
+})
+
+var parser2 = JSONStream.parse(['docs', /./])
+parser2.on('data', function(data) {
+ output[1].push(data)
+})
+
+var pending = 2
+function onend () {
+ if (--pending > 0) return
+ it(output).deepEqual([
+ [], [{hello: 'world'}]
+ ])
+ console.error('PASSED')
+}
+parser1.on('end', onend)
+parser2.on('end', onend)
+
+function makeReadableStream() {
+ var readStream = new stream.Stream()
+ readStream.readable = true
+ readStream.write = function (data) { this.emit('data', data) }
+ readStream.end = function (data) { this.emit('end') }
+ return readStream
+}
+
+var emptyArray = makeReadableStream()
+emptyArray.pipe(parser1)
+emptyArray.write('{"docs":[]}')
+emptyArray.end()
+
+var objectArray = makeReadableStream()
+objectArray.pipe(parser2)
+objectArray.write('{"docs":[{"hello":"world"}]}')
+objectArray.end()
View
4,030 js_JSONStream/node_modules/JSONStream/test/fixtures/all_npm.json
4,030 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
39 js_JSONStream/node_modules/JSONStream/test/fn.js
@@ -0,0 +1,39 @@
+
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, 'fixtures','all_npm.json')
+ , JSONStream = require('../')
+ , it = require('it-is')
+
+function fn (s) {
+ return !isNaN(parseInt(s, 10))
+}
+
+var expected = JSON.parse(fs.readFileSync(file))
+ , parser = JSONStream.parse(['rows', fn])
+ , called = 0
+ , ended = false
+ , parsed = []
+
+fs.createReadStream(file).pipe(parser)
+
+parser.on('data', function (data) {
+ called ++
+ it.has({
+ id: it.typeof('string'),
+ value: {rev: it.typeof('string')},
+ key:it.typeof('string')
+ })
+ parsed.push(data)
+})
+
+parser.on('end', function () {
+ ended = true
+})
+
+process.on('exit', function () {
+ it(called).equal(expected.rows.length)
+ it(parsed).deepEqual(expected.rows)
+ console.error('PASSED')
+})
View
42 js_JSONStream/node_modules/JSONStream/test/multiple_objects.js
@@ -0,0 +1,42 @@
+var fs = require ('fs');
+var net = require('net');
+var join = require('path').join;
+var file = join(__dirname, 'fixtures','all_npm.json');
+var it = require('it-is');
+var JSONStream = require('../');
+
+var str = fs.readFileSync(file);
+
+var datas = {}
+
+var server = net.createServer(function(client) {
+ var root_calls = 0;
+ var data_calls = 0;
+ var parser = JSONStream.parse(['rows', true, 'key']);
+ parser.on('root', function(root, count) {
+ ++ root_calls;
+ });
+
+ parser.on('data', function(data) {
+ ++ data_calls;
+ datas[data] = (datas[data] || 0) + 1
+ it(data).typeof('string')
+ });
+
+ parser.on('end', function() {
+ console.log('END')
+ var min = Infinity
+ for (var d in datas)
+ min = min > datas[d] ? datas[d] : min
+ it(root_calls).equal(3);
+ it(min).equal(3);
+ server.close();
+ });
+ client.pipe(parser);
+});
+server.listen(9999);
+
+var client = net.connect({ port : 9999 }, function() {
+ var msgs = str + ' ' + str + '\n\n' + str
+ client.end(msgs);
+});
View
35 js_JSONStream/node_modules/JSONStream/test/multiple_objects_error.js
@@ -0,0 +1,35 @@
+var fs = require ('fs');
+var net = require('net');
+var join = require('path').join;
+var file = join(__dirname, 'fixtures','all_npm.json');
+var it = require('it-is');
+var JSONStream = require('../');
+
+var str = fs.readFileSync(file);
+
+var server = net.createServer(function(client) {
+ var root_calls = 0;
+ var data_calls = 0;
+ var parser = JSONStream.parse();
+ parser.on('root', function(root, count) {
+ ++ root_calls;
+ it(root_calls).notEqual(2);
+ });
+
+ parser.on('error', function(err) {
+ console.log(err);
+ server.close();
+ });
+
+ parser.on('end', function() {
+ console.log('END');
+ server.close();
+ });
+ client.pipe(parser);
+});
+server.listen(9999);
+
+var client = net.connect({ port : 9999 }, function() {
+ var msgs = str + '}';
+ client.end(msgs);
+});
View
28 js_JSONStream/node_modules/JSONStream/test/parsejson.js
@@ -0,0 +1,28 @@
+
+
+/*
+ sometimes jsonparse changes numbers slightly.
+*/
+
+var r = Math.random()
+ , Parser = require('jsonparse')
+ , p = new Parser()
+ , assert = require('assert')
+ , times = 20
+while (times --) {
+
+ assert.equal(JSON.parse(JSON.stringify(r)), r, 'core JSON')
+
+ p.onValue = function (v) {
+ console.error('parsed', v)
+ assert.equal(
+ String(v).slice(0,12),
+ String(r).slice(0,12)
+ )
+ }
+ console.error('correct', r)
+ p.write (new Buffer(JSON.stringify([r])))
+
+
+
+}
View
41 js_JSONStream/node_modules/JSONStream/test/stringify.js
@@ -0,0 +1,41 @@
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, 'fixtures','all_npm.json')
+ , JSONStream = require('../')
+ , it = require('it-is').style('colour')
+
+ function randomObj () {
+ return (
+ Math.random () < 0.4
+ ? {hello: 'eonuhckmqjk',
+ whatever: 236515,
+ lies: true,
+ nothing: [null],
+ stuff: [Math.random(),Math.random(),Math.random()]
+ }
+ : ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]]
+ )
+ }
+
+var expected = []
+ , stringify = JSONStream.stringify()
+ , es = require('event-stream')
+ , stringified = ''
+ , called = 0
+ , count = 10
+ , ended = false
+
+while (count --)
+ expected.push(randomObj())
+
+ es.connect(
+ es.readArray(expected),
+ stringify,
+ //JSONStream.parse([/./]),
+ es.writeArray(function (err, lines) {
+
+ it(JSON.parse(lines.join(''))).deepEqual(expected)
+ console.error('PASSED')
+ })
+ )
View
47 js_JSONStream/node_modules/JSONStream/test/stringify_object.js
@@ -0,0 +1,47 @@
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, 'fixtures','all_npm.json')
+ , JSONStream = require('../')
+ , it = require('it-is').style('colour')
+ , es = require('event-stream')
+ , pending = 10
+ , passed = true
+
+ function randomObj () {
+ return (
+ Math.random () < 0.4
+ ? {hello: 'eonuhckmqjk',
+ whatever: 236515,
+ lies: true,
+ nothing: [null],
+ stuff: [Math.random(),Math.random(),Math.random()]
+ }
+ : ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]]
+ )
+ }
+
+for (var ix = 0; ix < pending; ix++) (function (count) {
+ var expected = {}
+ , stringify = JSONStream.stringifyObject()
+
+ es.connect(
+ stringify,
+ es.writeArray(function (err, lines) {
+ it(JSON.parse(lines.join(''))).deepEqual(expected)
+ if (--pending === 0) {
+ console.error('PASSED')
+ }
+ })
+ )
+
+ while (count --) {
+ var key = Math.random().toString(16).slice(2)
+ expected[key] = randomObj()
+ stringify.write([ key, expected[key] ])
+ }
+
+ process.nextTick(function () {
+ stringify.end()
+ })
+})(ix)
View
35 js_JSONStream/node_modules/JSONStream/test/test.js
@@ -0,0 +1,35 @@
+
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, 'fixtures','all_npm.json')
+ , JSONStream = require('../')
+ , it = require('it-is')
+
+var expected = JSON.parse(fs.readFileSync(file))
+ , parser = JSONStream.parse(['rows', /\d+/ /*, 'value'*/])
+ , called = 0
+ , ended = false
+ , parsed = []
+
+fs.createReadStream(file).pipe(parser)
+
+parser.on('data', function (data) {
+ called ++
+ it.has({
+ id: it.typeof('string'),
+ value: {rev: it.typeof('string')},
+ key:it.typeof('string')
+ })
+ parsed.push(data)
+})
+
+parser.on('end', function () {
+ ended = true
+})
+
+process.on('exit', function () {
+ it(called).equal(expected.rows.length)
+ it(parsed).deepEqual(expected.rows)
+ console.error('PASSED')
+})
View
29 js_JSONStream/node_modules/JSONStream/test/test2.js
@@ -0,0 +1,29 @@
+
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, '..','package.json')
+ , JSONStream = require('../')
+ , it = require('it-is')
+
+var expected = JSON.parse(fs.readFileSync(file))
+ , parser = JSONStream.parse([])
+ , called = 0
+ , ended = false
+ , parsed = []
+
+fs.createReadStream(file).pipe(parser)
+
+parser.on('data', function (data) {
+ called ++
+ it(data).deepEqual(expected)
+})
+
+parser.on('end', function () {
+ ended = true
+})
+
+process.on('exit', function () {
+ it(called).equal(1)
+ console.error('PASSED')
+})
View
41 js_JSONStream/node_modules/JSONStream/test/two-ways.js
@@ -0,0 +1,41 @@
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, 'fixtures','all_npm.json')
+ , JSONStream = require('../')
+ , it = require('it-is').style('colour')
+
+ function randomObj () {
+ return (
+ Math.random () < 0.4
+ ? {hello: 'eonuhckmqjk',
+ whatever: 236515,
+ lies: true,
+ nothing: [null],
+// stuff: [Math.random(),Math.random(),Math.random()]
+ }
+ : ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]]
+ )
+ }
+
+var expected = []
+ , stringify = JSONStream.stringify()
+ , es = require('event-stream')
+ , stringified = ''
+ , called = 0
+ , count = 10
+ , ended = false
+
+while (count --)
+ expected.push(randomObj())
+
+ es.connect(
+ es.readArray(expected),
+ stringify,
+ JSONStream.parse([/./]),
+ es.writeArray(function (err, lines) {
+
+ it(lines).has(expected)
+ console.error('PASSED')
+ })
+ )
View
6 javascript/package.json → js_JSONStream/package.json
@@ -1,10 +1,10 @@
{
- "name": "test json parsing",
+ "name": "json_stream_benchmark",
"description": "Sample jso parsing benhmarking",
+ "version" : "0.0.1",
"author": "Avner Cohen <israbirding@gmail.com>",
"dependencies": {
- "JSONStream": "",
- "node-json-streams": ""
+ "JSONStream": ""
},
"engine": {"node" : ">=0.8"}
}
View
32 js_JSONStream/run.js
@@ -0,0 +1,32 @@
+#!/usr/local/bin/node
+var fs = require('fs');
+var JSONStream = require('JSONStream');
+var stream = JSONStream.parse(["rows", true]);
+
+var jsonFile = process.argv[2]; //File name sent in from the marshaller
+
+if (jsonFile === "" || typeof jsonFile === "undefined"){
+ console.log("No file sent for parsing");
+ return false;
+}
+
+var totalRows = 0;
+console.time("Parse");
+stream.on("start", function(){
+ totalRows = 0;
+
+});
+
+stream.on("data", function(){
+ totalRows++;
+});
+
+stream.on("end", function(){
+ //console.log(totalRows + " Total rows.");
+ console.timeEnd("Parse");
+
+});
+
+var fileStream = fs.createReadStream(jsonFile);
+
+fileStream.pipe(stream);
View
13 readme.md
@@ -0,0 +1,13 @@
+Benchmarking Streaming JSON implementations
+====
+
+This is a simple project illustrating testing of various json implementaions that are based on streaming api, i.e. low memory footprint and unix like coding style.
+
+The dummy jason as based on the data from the npm repository.
+
+Intention is to try and add more and more implementaions or languages testing on this.
+
+
+To run execute the ruby script at the project's root:
+
+ ruby benchmark.rb

0 comments on commit 13b4e93

Please sign in to comment.
Something went wrong with that request. Please try again.