Skip to content

Commit 5036fd4

Browse files
mbcmholt
authored andcommitted
add command-line flag to support very big json objs. (#66)
1 parent f223e87 commit 5036fd4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

json-to-go.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,21 @@ function jsonToGo(json, typename, flatten = true)
398398

399399
if (typeof module != 'undefined') {
400400
if (!module.parent) {
401-
process.stdin.on('data', function(buf) {
402-
const json = buf.toString('utf8')
403-
console.log(jsonToGo(json).go)
404-
})
401+
if (process.argv.length > 2 && process.argv[2] === '-big') {
402+
bufs = []
403+
process.stdin.on('data', function(buf) {
404+
bufs.push(buf)
405+
})
406+
process.stdin.on('end', function() {
407+
const json = Buffer.concat(bufs).toString('utf8')
408+
console.log(jsonToGo(json).go)
409+
})
410+
} else {
411+
process.stdin.on('data', function(buf) {
412+
const json = buf.toString('utf8')
413+
console.log(jsonToGo(json).go)
414+
})
415+
}
405416
} else {
406417
module.exports = jsonToGo
407418
}

0 commit comments

Comments
 (0)