Skip to content

Instantly share code, notes, and snippets.

@joehand
Created October 20, 2017 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehand/a333396a1963ecd0bd31231788dfaebd to your computer and use it in GitHub Desktop.
Save joehand/a333396a1963ecd0bd31231788dfaebd to your computer and use it in GitHub Desktop.
grab portals via hypercore-archiver
var archiver = require('hypercore-archiver')
var swarm = require('hypercore-archiver/swarm')
var ram = require('random-access-memory')
var hyperdrive = require('hyperdrive')
var discovery = require('hyperdiscovery')
module.exports = function (rotondeKey) {
var portals = archiver('./data', {sparse: true})
swarm(portals)
var archive = hyperdrive(ram, rotondeKey)
archive.on('ready', function () {
discovery(archive)
})
archive.readFile('/portal.json', 'utf8', function (err, data) {
if (err) throw err
addPortals(JSON.parse(data).port)
})
function addPortals (data) {
data.map(function (portal) {
portals.add(portal)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment