New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

hyperdrive-index

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperdrive-index

index changes to a hyperdrive feed

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
2
-50%
Maintainers
1
Weekly downloads
 
Created
Source

hyperdrive-index

index changes to a hyperdrive feed

Use this package to generate indexes to quickly answer questions about files written to hyperdrive. For example, you could create an index that parses exif headers and generates thumbnails for a p2p photo album served over a hyperdrive.

example

This example indexes the number of lines in each file written to hyperdrive.

var level = require('level')
var hyperdrive = require('hyperdrive')
var through = require('through2')
var split = require('split2')
var hdex = require('hyperdrive-index')

var db = level('/tmp/drive.db')
var archive = hyperdrive('/tmp/drive.data')

var dex = hdex({
  archive: archive,
  db: level('/tmp/drive.dex.db'),
  map: function (entry, cb) {
    var ch = archive.checkout(entry.version)
    var stream = ch.createReadStream(entry.name)
    countLines(stream, function (err, lines) {
      if (err) cb(err)
      else db.put(entry.name, lines, cb)
    })
  }
})

var name = process.argv[3]
if (process.argv[2] === 'add') {
  process.stdin.pipe(archive.createWriteStream(name))
} else if (process.argv[2] === 'get') {
  dex.ready(function () {
    db.get(name, function (err, lines) {
      if (err) console.error(err)
      else console.log(lines)
    })
  })
}

function countLines (stream, cb) {
  var n = 0
  stream.pipe(split()).pipe(through(write, end))
  function write (buf, enc, next) { n++; next() }
  function end (next) { cb(null, n) }
}
$ echo -ne 'one\ntwo\nthree' | node dex.js add /hello.txt
$ echo -ne 'wheee' | node dex.js add /what.txt
$ node dex.js get /what.txt
1
$ node dex.js get /hello.txt
3
$ echo -ne 'one\ntwo\nthree\nfour\nfive' | node dex.js add /hello.txt
$ node dex.js get /hello.txt
5

api

var hindex = require('hyperdrive-index')

var dex = hindex(opts)

Create a hyperdrive index dex from:

  • opts.archive - hyperdrive archive opened in live mode
  • opts.db - leveldb instance
  • opts.map(entry, cb) - function to process each new entry object

In your opts.map(entry, cb) function, write your indexes to some persistent storage and call cb(err) when finished. The entry records are metadata objects, like you get from archive.list().

dex.ready(fn)

fn() fires when the indexes are caught up with the latest known value in the hyperdrive feed.

install

npm install hyperdrive-index

license

BSD

Keywords

hyperdrive

FAQs

Package last updated on 22 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts