New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

level-hooks

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-hooks

pre/post hooks for leveldb

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
131K
increased by6.52%
Maintainers
1
Weekly downloads
 
Created
Source

Pre/Post hooks for leveldb

Intercept put/delete/batch operations on levelup.

var levelup   = require('levelup')
var timestamp = require('monotonic-timestamp')
var hooks     = require('level-hooks')

levelup(file, {createIfMissing: true}, function (err, db) {

  //install hooks onto db.
  hooks()(db)

  db.hooks.pre(function (batch) {

    //batch is the same format as the arguments to db.batch.
    //it may be mutated like this to atomically add operations.
    
    //example, add a log to record every put operation.
    batch.forEach(function (e) {

      if(!/~log-/.test(e.key.toString())
        batch.push({type: 'put', key: '~log-'+timestamp()+'-'+e.type, value: e.key})

    })

    //you can also remove elements.
    //if there is only one element,
    //hooks will turn it into an put/del operation, 
    //not use the batch function.

  })

  //add a hook that responds after an operation has completed.

  //same pattern as the an element in the batch array.
  db.hooks.post(function (err, ch) {
    console.log(ch)
    //{type: 'put'|'del', key: ..., value: ...}
  })


})

Used by map-reduce to make map-reduce durable across crashes!

FAQs

Package last updated on 18 Dec 2012

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc