Last active
June 22, 2016 17:15
-
-
Save bcomnes/5df0c6698788eff7c21aaf77e077a583 to your computer and use it in GitHub Desktop.
Testing random-access-http and hypercore
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
node_modules | |
*.db | |
*.mp4 |
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 file = require('random-access-file') | |
var level = require('level') | |
var db = level('test.db') | |
var hypercore = require('hypercore') | |
var fs = require('fs') | |
var pump = require('pump') | |
var core = hypercore(db) | |
var feed = core.createFeed({ | |
storage: file('/dev/null'), | |
live: false | |
}) | |
pump(fs.createReadStream('Popeye_Nearlyweds_512kb.mp4'), feed.createWriteStream(), function (err) { | |
if (err) throw err | |
console.log('key is', feed.key.toString('hex')) | |
}) |
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 file = require('random-access-file') | |
var level = require('level') | |
var anotherDb = level('anotherDb.db') | |
var swarm = require('hyperdrive-archive-swarm') | |
var hypercore = require('hypercore') | |
var core = hypercore(anotherDb) | |
var feed = core.createFeed('6b8d8a41ba6c3ec76862d0dbd6210e114447b9ce8250b0909175f77b5d6c4245', { | |
storage: file('test-clone.mp4') | |
}) | |
feed.on('download', function (block, data) { | |
console.log(block) | |
}) | |
feed.on('upload', function (block, data) { | |
console.log(block) | |
}) | |
feed.on('open', function (discoveryKey) { | |
console.log(discoveryKey) | |
}) | |
swarm(feed) |
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
{ | |
"name": "testrun", | |
"version": "1.0.0", | |
"description": "", | |
"main": "generate.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"hypercore": "^4.2.7", | |
"hyperdrive-archive-swarm": "^3.0.1", | |
"level": "^1.4.0", | |
"pump": "^1.0.1", | |
"random-access-file": "^1.2.0", | |
"random-access-http": "^1.0.1" | |
} | |
} |
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
wget https://ia800309.us.archive.org/2/items/Popeye_Nearlyweds/Popeye_Nearlyweds_512kb.mp4 |
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 http = require('random-access-http') | |
var level = require('level') | |
var db = level('test.db') | |
var hypercore = require('hypercore') | |
var swarm = require('hyperdrive-archive-swarm') | |
var core = hypercore(db) | |
var feed = core.createFeed('6b8d8a41ba6c3ec76862d0dbd6210e114447b9ce8250b0909175f77b5d6c4245', { | |
storage: http('https://ia800309.us.archive.org/2/items/Popeye_Nearlyweds/Popeye_Nearlyweds_512kb.mp4') | |
}) | |
feed.on('download', function (block, data) { | |
console.log(block) | |
}) | |
feed.on('upload', function (block, data) { | |
console.log(block) | |
}) | |
feed.on('open', function (discoveryKey) { | |
console.log(discoveryKey) | |
}) | |
swarm(feed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/mafintosh/7c6b0c56619bd2a43a81b5e6756d158d