stream-json
Advanced tools
Comparing version 0.0.1 to 0.0.3
@@ -98,2 +98,3 @@ var util = require("util"); | ||
this._sync(); | ||
callback(); | ||
} | ||
@@ -100,0 +101,0 @@ |
@@ -7,3 +7,3 @@ var Parser = require("./Parser"); | ||
function makeJsonSource(options){ | ||
function createSource(options){ | ||
var streams = [new Parser(options), new Streamer(options)]; | ||
@@ -23,2 +23,2 @@ if(options && ("packKeys" in options || "packStrings" in options || "packNumbers" in options)){ | ||
module.exports = makeJsonSource; | ||
module.exports = createSource; |
{ | ||
"name": "stream-json", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"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", |
@@ -12,3 +12,3 @@ # stream-json [](http://travis-ci.org/uhop/stream-json) | ||
* `Emitter`, which converts an event stream into events by bridging `stream.Writable` with `EventEmitter`. | ||
* `Source`, which is a helper that connect streams using `pipe()` and converts an event stream on the end of pipe into events, similar to `Emitter`. | ||
* `Source`, which is a helper that connects streams using `pipe()` and converts an event stream on the end of pipe into events, similar to `Emitter`. | ||
@@ -35,3 +35,2 @@ Additionally a helper function is available in the main file, which creates a `Source` object with a default set of stream components. | ||
source.on("startObject", function(){ ++objectCounter; }); | ||
source.on("nullValue", function(){ ++nullCounter; }); | ||
@@ -56,3 +55,3 @@ source.on("end", function(){ | ||
This is the work horse of the package. It is a transform stream, which consumes text, and produces a stream of tokens. It is always the first in a pipe chain being directly fed with a text from a file, a socket, the standard input, or any other text stream. | ||
This is the workhorse of the package. It is a transform stream, which consumes text, and produces a stream of tokens. It is always the first in a pipe chain being directly fed with a text from a file, a socket, the standard input, or any other text stream. | ||
@@ -167,3 +166,3 @@ Its `Writeable` part operates in a buffer mode, while its `Readable` part operates in an [objectMode](http://nodejs.org/api/stream.html#stream_object_mode). | ||
`numberValue` event always follows `endNumber`. | ||
`value` of this event is a string, not a number. If user wants to convert it to a number, they can do it yourself. The simplest way to do it (assuming your platform and JavaScript can handle it), is to force it to number: | ||
`value` of this event is a string, not a number. If user wants to convert it to a number, they can do it themselves. The simplest way to do it (assuming your platform and JavaScript can handle it), is to force it to a number: | ||
@@ -303,3 +302,3 @@ ```js | ||
1. If any of them are `true`, a `Packer` instance is created with `options`, and added to the pipe. | ||
2. If all of them unspecified, all pack flags are assumed to be `true`, and a `Packer` is created and added. | ||
2. If all of them are unspecified, all pack flags are assumed to be `true`, and a `Packer` is created and added. | ||
3. If any of them are specified, yet all are `false`, `Packer` is not added. | ||
@@ -321,3 +320,3 @@ | ||
The test file `tests/sample.json` is copied as is from an open source project [json-simple](https://code.google.com/p/json-simple/) under Apache License 2.0. | ||
The test file `tests/sample.json.gz` is copied as is from an open source project [json-simple](https://code.google.com/p/json-simple/) under Apache License 2.0 and compressed with gzip. | ||
@@ -358,2 +357,2 @@ ## Apendix A: tokens | ||
* `,`: separates components of an array, or an object. | ||
* `:`: separates a key and its value in an object literal. | ||
* `:`: separates a key and its value in an object literal. |
var createSource = require("../main"); | ||
var ReadString = require("./ReadString"); | ||
var fs = require("fs"), path = require("path"); | ||
var fs = require("fs"), path = require("path"), zlib = require("zlib"); | ||
@@ -32,7 +32,12 @@ | ||
fs.readFile(path.resolve(__dirname, "sample.json"), "utf8", function(err, data){ | ||
fs.readFile(path.resolve(__dirname, "sample.json.gz"), function(err, data){ | ||
if(err){ | ||
throw err; | ||
} | ||
new ReadString(data).pipe(source.input); | ||
zlib.gunzip(data, function(err, data){ | ||
if(err){ | ||
throw err; | ||
} | ||
new ReadString(data).pipe(source.input); | ||
}); | ||
}); |
@@ -9,3 +9,2 @@ var ReadString = require("./ReadString"); | ||
var input = '{"a": 1, "b": true, "c": ["d"]}'; | ||
//var input = '{"a": [1]}'; | ||
@@ -12,0 +11,0 @@ |
var createSource = require("../main"); | ||
var fs = require("fs"), path = require("path"); | ||
var fs = require("fs"), path = require("path"), zlib = require("zlib"); | ||
@@ -31,2 +31,3 @@ | ||
fs.createReadStream(path.resolve(__dirname, "sample.json")).pipe(source.input); | ||
fs.createReadStream(path.resolve(__dirname, "sample.json.gz")). | ||
pipe(zlib.createGunzip()).pipe(source.input); |
@@ -1,2 +0,2 @@ | ||
var fs = require("fs"), path = require("path"); | ||
var fs = require("fs"), path = require("path"), zlib = require("zlib"); | ||
@@ -7,19 +7,24 @@ | ||
fs.readFile(path.resolve(__dirname, "sample.json"), "utf8", function(err, data){ | ||
fs.readFile(path.resolve(__dirname, "sample.json.gz"), function(err, data){ | ||
if(err){ | ||
throw err; | ||
} | ||
zlib.gunzip(data, function(err, data){ | ||
if(err){ | ||
throw err; | ||
} | ||
var o = JSON.parse(data); | ||
var o = JSON.parse(data); | ||
walk(o); | ||
walk(o); | ||
console.log("objects:", objectCounter); | ||
console.log("arrays:", arrayCounter); | ||
console.log("keys:", keyCounter); | ||
console.log("strings:", stringCounter); | ||
console.log("numbers:", numberCounter); | ||
console.log("nulls:", nullCounter); | ||
console.log("trues:", trueCounter); | ||
console.log("falses:", falseCounter); | ||
console.log("objects:", objectCounter); | ||
console.log("arrays:", arrayCounter); | ||
console.log("keys:", keyCounter); | ||
console.log("strings:", stringCounter); | ||
console.log("numbers:", numberCounter); | ||
console.log("nulls:", nullCounter); | ||
console.log("trues:", trueCounter); | ||
console.log("falses:", falseCounter); | ||
}); | ||
}); | ||
@@ -26,0 +31,0 @@ |
@@ -5,3 +5,3 @@ var Source = require("../Source"); | ||
var fs = require("fs"), path = require("path"); | ||
var fs = require("fs"), path = require("path"), zlib = require("zlib"); | ||
@@ -34,2 +34,3 @@ | ||
fs.createReadStream(path.resolve(__dirname, "sample.json"), {encoding: "utf8"}).pipe(source.input); | ||
fs.createReadStream(path.resolve(__dirname, "sample.json.gz")). | ||
pipe(zlib.createGunzip()).pipe(source.input); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
192590
669
1