Skip to content

Instantly share code, notes, and snippets.

@pfrazee
Created June 11, 2016 14:37
Show Gist options
  • Save pfrazee/28feb6d06b1f2fdea5e5bb69fa5548e2 to your computer and use it in GitHub Desktop.
Save pfrazee/28feb6d06b1f2fdea5e5bb69fa5548e2 to your computer and use it in GitHub Desktop.
var hyperdrive = require('hyperdrive')
var swarm = require('hyperdrive-archive-swarm')
var memdb = require('memdb')
var fs = require('fs')
var path = require('path')
var drive = hyperdrive(memdb())
var archive = drive.createArchive()
// index.html
var ws = archive.createFileWriteStream('index.html')
ws.write(`
<!doctype html>
<html>
<head><title>Test dat site</title></head>
<body>
<h1>Hello, dat world</h1>
<img src="/icon.png">
</body>
</html>
`)
ws.end()
// icon.png
var ws = archive.createFileWriteStream('icon.png')
fs.createReadStream(path.join(__dirname,'../resources/icon.png')).pipe(ws)
// done
archive.finalize(function () {
var link = archive.key.toString('hex')
console.log('dat://'+link+'/')
console.log('Swarming...')
var sw = swarm(archive)
sw.on('peer', function (peer) {
var e = new Error()
console.log('New swarm peer:', peer, e.stack)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment