Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

JSONStream

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

JSONStream - npm Package Compare versions

Comparing version 0.4.4 to 0.5.0

100

index.js
var Parser = require('jsonparse')
, Stream = require('stream').Stream
, through = require('through')

@@ -15,4 +16,22 @@ /*

var stream = new Stream()
var parser = new Parser()
var stream = through(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)
},
function (data) {
if(data)
stream.write(data)
stream.queue(null)
})
var count = 0

@@ -51,3 +70,3 @@ if(!path || !path.length)

count ++
stream.emit('data', this.value[this.key])
stream.queue(this.value[this.key])
for(var i in this.stack)

@@ -64,3 +83,3 @@ this.stack[i].value = {}

if(!path)
stream.emit('data', stream.root)
stream.queue(stream.root)
stream.emit('root', stream.root, count)

@@ -76,25 +95,3 @@ count = 0;

}
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');
}

@@ -131,25 +128,18 @@ return stream

var stream = new Stream ()
var stream
, first = true
, ended = false
, anyData = false
stream.write = function (data) {
stream = through(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)
if(first) { first = false ; stream.queue(op + json)}
else stream.queue(sep + json)
},
function (data) {
if(!anyData)
stream.queue(op)
stream.queue(cl)
stream.queue(null)
})
stream.emit('end')
}
stream.writable = true
stream.readable = true
return stream

@@ -175,23 +165,17 @@ }

, first = true
, ended = false
, anyData = false
stream.write = function (data) {
stream = through(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)
if(first) { first = false ; stream.queue(op + json)}
else stream.queue(sep + json)
},
function (data) {
if(!anyData) stream.queue(op)
stream.queue(cl)
stream.emit('end')
}
stream.writable = true
stream.readable = true
stream.queue(null)
})
return stream
}
{
"name": "JSONStream",
"version": "0.4.4",
"version": "0.5.0",
"description": "rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)",

@@ -11,3 +11,4 @@ "homepage": "http://github.com/dominictarr/JSONStream",

"dependencies": {
"jsonparse": "0.0.5"
"jsonparse": "0.0.5",
"through": "~2.2.7"
},

@@ -14,0 +15,0 @@ "devDependencies": {

@@ -10,3 +10,4 @@ var fs = require ('fs');

var parser = JSONStream.parse([]);
parser.on('close', function() {
parser.on('end', function() {
console.log('close')
console.error('PASSED');

@@ -16,3 +17,7 @@ server.close();

client.pipe(parser);
client.destroy();
var n = 4
client.on('data', function () {
if(--n) return
client.end();
})
});

@@ -23,3 +28,3 @@ server.listen(9999);

var client = net.connect({ port : 9999 }, function() {
fs.createReadStream(file).pipe(client);
fs.createReadStream(file).pipe(client).on('data', console.log) //.resume();
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc