JSONStream
Advanced tools
Comparing version 0.0.0 to 0.1.0
44
index.js
@@ -11,4 +11,2 @@ | ||
so i'll forgive him. | ||
@@ -71,2 +69,4 @@ */ | ||
stream.write = function (chunk) { | ||
if('string' === typeof chunk) | ||
chunk = new Buffer(chunk) | ||
parser.write(chunk) | ||
@@ -82,2 +82,42 @@ } | ||
return stream | ||
} | ||
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 eve you like | ||
var stream = new Stream () | ||
, first = true | ||
, ended = false | ||
stream.write = function (data) { | ||
var json = JSON.stringify(data) | ||
if(first) { first = false ; stream.emit('data', op + json)} | ||
else stream.emit('data', sep + json) | ||
} | ||
stream.end = function (data) { | ||
console.error('END ****************',JSON.stringify(cl)) | ||
if(ended) | ||
return | ||
ended = true | ||
// if(data) | ||
// stream.write(data) | ||
stream.emit('data', cl) | ||
stream.emit('end') | ||
} | ||
stream.writable = true | ||
stream.readable = true | ||
return stream | ||
} |
{ "name": "JSONStream" | ||
, "version": "0.0.0" | ||
, "version": "0.1.0" | ||
, "description": "rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)" | ||
@@ -4,0 +4,0 @@ , "homepage": "http://github.com/dominictarr/JSONStream" |
Sorry, the diff of this file is not supported yet
379827
11
4273
105
4