Created
October 20, 2017 17:51
-
-
Save joehand/a333396a1963ecd0bd31231788dfaebd to your computer and use it in GitHub Desktop.
grab portals via hypercore-archiver
This file contains hidden or 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
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