Last active
December 4, 2016 20:28
-
-
Save blahah/df00dfab55e63b3ccb30cc5ba5dd47d3 to your computer and use it in GitHub Desktop.
hyperdrive + pages usage
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
const level = require('level') | |
const hyperdrive = require('hyperdrive') | |
const discover = require('hyperdiscovery') | |
const pages = require('random-access-page-files') | |
const key = '154624e28aabcdf52625769f7b42361b4f7dafe53a14d27035d9ea9878262e16' | |
const drive = hyperdrive(level('./test_pages.hd')) | |
const archive = drive.createArchive( | |
new Buffer(key, 'hex'), | |
{ | |
live: false, | |
sparse: true, | |
storage: pages('./test_pages.storage') | |
} | |
) | |
discover(archive) | |
let n = 0 | |
archive.list({ live: false }) | |
.on('data', entry => { | |
n++ | |
if (n < 10 && entry.type === 'file') { | |
archive.download(entry, err => { | |
if (err) console.error('download error', err) | |
}) | |
} | |
}) | |
.on('end', () => console.log(`listed ${n} entries`)) | |
.on('error', err => console.error('listing error', err)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment