Last active
October 5, 2016 11:28
-
-
Save devinivy/995e64017bd949f66e79ebbc5318e42e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"web-app": { | |
"servlet": [ | |
{ | |
"servlet-name": "cofaxCDS", | |
"servlet-class": "org.cofax.cds.CDSServlet", | |
"init-param": { | |
"configGlossary:installationAt": "Philadelphia, PA", | |
"configGlossary:adminEmail": "[email protected]", | |
"configGlossary:poweredBy": "Cofax", | |
"configGlossary:poweredByIcon": "/images/cofax.gif", | |
"configGlossary:staticPath": "/content/static", | |
"templateProcessorClass": "org.cofax.WysiwygTemplate", | |
"templateLoaderClass": "org.cofax.FilesTemplateLoader", | |
"templatePath": "templates", | |
"templateOverridePath": "", | |
"defaultListTemplate": "listTemplate.htm", | |
"defaultFileTemplate": "articleTemplate.htm", | |
"useJSP": false, | |
"jspListTemplate": "listTemplate.jsp", | |
"jspFileTemplate": "articleTemplate.jsp", | |
"cachePackageTagsTrack": 200, | |
"cachePackageTagsStore": 200, | |
"cachePackageTagsRefresh": 60, | |
"cacheTemplatesTrack": 100, | |
"cacheTemplatesStore": 50, | |
"cacheTemplatesRefresh": 15, | |
"cachePagesTrack": 200, | |
"cachePagesStore": 100, | |
"cachePagesRefresh": 10, | |
"cachePagesDirtyRead": 10, | |
"searchEngineListTemplate": "forSearchEnginesList.htm", | |
"searchEngineFileTemplate": "forSearchEngines.htm", | |
"searchEngineRobotsDb": "WEB-INF/robots.db", | |
"useDataStore": true, | |
"dataStoreClass": "org.cofax.SqlDataStore", | |
"redirectionClass": "org.cofax.SqlRedirection", | |
"dataStoreName": "cofax", | |
"dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", | |
"dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", | |
"dataStoreUser": "sa", | |
"dataStorePassword": "dataStoreTestQuery", | |
"dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", | |
"dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", | |
"dataStoreInitConns": 10, | |
"dataStoreMaxConns": 100, | |
"dataStoreConnUsageLimit": 100, | |
"dataStoreLogLevel": "debug", | |
"maxUrlLength": 500}}, | |
{ | |
"servlet-name": "cofaxEmail", | |
"servlet-class": "org.cofax.cds.EmailServlet", | |
"init-param": { | |
"mailHost": "mail1", | |
"mailHostOverride": "mail2"}}, | |
{ | |
"servlet-name": "cofaxAdmin", | |
"servlet-class": "org.cofax.cds.AdminServlet"}, | |
{ | |
"servlet-name": "fileServlet", | |
"servlet-class": "org.cofax.cds.FileServlet"}, | |
{ | |
"servlet-name": "cofaxTools", | |
"servlet-class": "org.cofax.cms.CofaxToolsServlet", | |
"init-param": { | |
"templatePath": "toolstemplates/", | |
"log": 1, | |
"logLocation": "/usr/local/tomcat/logs/CofaxTools.log", | |
"logMaxSize": "", | |
"dataLog": 1, | |
"dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", | |
"dataLogMaxSize": "", | |
"removePageCache": "/content/admin/remove?cache=pages&id=", | |
"removeTemplateCache": "/content/admin/remove?cache=templates&id=", | |
"fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", | |
"lookInContext": 1, | |
"adminGroupID": 4, | |
"betaServer": true}}], | |
"servlet-mapping": { | |
"cofaxCDS": "/", | |
"cofaxEmail": "/cofaxutil/aemail/*", | |
"cofaxAdmin": "/admin/*", | |
"fileServlet": "/static/*", | |
"cofaxTools": "/tools/*"}, | |
"taglib": { | |
"taglib-uri": "cofax.tld", | |
"taglib-location": "/WEB-INF/tlds/cofax.tld"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Fs = require('fs'); | |
const Stream = require('stream'); | |
const JsonDepthStream = require('json-depth-stream'); | |
const internals = {}; | |
internals.firstArrayItem = (itemPath, arrayPath) => { | |
if (itemPath.length !== arrayPath.length + 1) { | |
return false; | |
} | |
if (itemPath[itemPath.length - 1] !== 0) { | |
return false; | |
} | |
for (let i = 0; i < arrayPath.length; ++i) { | |
if (itemPath[i] !== arrayPath[i]) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
const JsonArrayStream = class extends Stream.Transform { | |
constructor(path) { | |
super({ readableObjectMode: true }); | |
this.path = path || []; | |
this.depth = this.path.length + 1; | |
this.json = new JsonDepthStream(this.depth); | |
this.hadSplit = false; | |
this.hasStartedItem = false; | |
this.currentChunk = null; | |
this.backlog = { start: null, buffers: [] }; | |
this.started = false; | |
this._boundSplit = this._split.bind(this); | |
this.json.on('split', this._boundSplit); | |
} | |
_transform(chk, enc, cb) { | |
this.currentChunk = chk; | |
this.hadSplit = false; | |
this.json.update(chk); | |
// Now zero or many splits may occur, causing pushes | |
if (!this.hadSplit && this.hasStartedItem) { | |
this.backlog.chunks.push(this.currentChunk); | |
} | |
cb(); | |
} | |
_split(path, index) { | |
// Has not started splitting yet | |
if (!this.started && !internals.firstArrayItem(path, this.path)) { | |
return; | |
} | |
// Else? | |
if (this.started && path.length !== this.depth) { | |
return this.json.removeListener('split', this._boundSplit); | |
} | |
this.started = true; | |
if (this.hasStartedItem) { | |
if (this.backlog.chunks.length === 1 && this.backlog.chunks[0] === this.currentChunk) { | |
// Starting and ending in same chunk | |
this.push(JSON.parse(this.currentChunk.slice(this.backlog.start, index).toString())); | |
} | |
else { | |
const buffers = []; | |
// From first chunk | |
buffers.push(this.backlog.chunks[0].slice(this.backlog.start)); // Starting point til end of first buffer) | |
// Could be zero or many middle chunks | |
for (let i = 1; i < this.backlog.chunks.length; i++) { | |
buffers.push(this.backlog.chunks[i]); | |
} | |
// From final chunk | |
buffers.push(this.currentChunk.slice(0, index)); | |
this.push(JSON.parse(Buffer.concat(buffers).toString())); | |
} | |
} | |
else { | |
this.backlog.start = index; | |
this.backlog.chunks = [this.currentChunk]; | |
} | |
this.hadSplit = true; | |
this.hasStartedItem = !this.hasStartedItem; | |
} | |
}; | |
const file = Fs.createReadStream(`${__dirname}/example.json`, { highWaterMark: 1024 }); | |
file.pipe(new JsonArrayStream(['web-app', 'servlet'])) | |
.on('data', (x) => console.log(x)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment