{"size": 874, "ext": "js", "max_stars_repo_path": "remoteLevel.js", "max_stars_repo_name": "kessler/gcm-server", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "remoteLevel.js", "max_issues_repo_name": "kessler/gcm-server", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "remoteLevel.js", "max_forks_repo_name": "kessler/gcm-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9714285714, "max_line_length": 151, "alphanum_fraction": 0.6773455378}
const multilevel = require('multilevel')
const net = require('net')
const pump = require('pump')
const log = require('./log')('remoteLevel')

// dangerous!
//const manifest = require('@reason/kiron-dish/manifest.json')

module.exports = details => {

	let db = multilevel.client()
	let con = net.connect(details.port, details.address)
	
	pump(con, db.createRpcStream(), con, err => {
		if (err) {
			log.error('error in multilevel stream', err)
			throw err
		}

		con.end()

		log.silly('remoteLevel stream finished')
	})

	con.setKeepAlive(true)

	con.once('connect', () => log.silly('remoteLevel connected'))

	return db
}

if (require.main === module) {
	let db = module.exports({ port: 9000, address: 'localhost' })
	db.createReadStream({ keyEncoding: 'string', valueEnconding: 'json' }).on('data', entry => console.log(entry.key.toString(), JSON.parse(entry.value)))
}