How to use subleveldown - 5 common examples

To help you get started, we’ve selected a few subleveldown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beakerbrowser / beaker / app / background-process / networks / dat.js View on Github external
export function setup () {
  // open databases
  dbPath = path.join(app.getPath('userData'), 'Hyperdrive')
  mkdirp.sync(path.join(dbPath, 'Archives')) // make sure the folders exist
  db = level(dbPath)
  archiveMetaDb = subleveldown(db, 'archive-meta', { valueEncoding: 'json' })
  subscribedArchivesDb = subleveldown(db, 'subscribed-archives', { valueEncoding: 'json' })
  ownedArchivesDb = subleveldown(db, 'owned-archives', { valueEncoding: 'json' })
  drive = hyperdrive(db)

  // watch archives for FS changes
  var watcher = chokidar.watch(path.join(dbPath, 'Archives'), { persistent: true, cwd: path.join(dbPath, 'Archives') })
  watcher.on('ready', () => { // wait till ready, otherwise we get an 'add' for each existing file
    watcher.on('add', onArchiveFSChange.bind(null, 'add', 'file'))
    watcher.on('addDir', onArchiveFSChange.bind(null, 'add', 'directory'))
    watcher.on('change', onArchiveFSChange.bind(null, 'change', 'file'))
    // watcher.on('unlink', onArchiveFSChange.bind(null, 'unlink', 'file')) TODO: dat doesnt support deletes yet
    // watcher.on('unlinkDir', onArchiveFSChange.bind(null, 'unlink', 'directory')) TODO: dat doesnt support deletes yet
  })
  app.once('will-quit', () => watcher.close())

  // create webrtc
  wrtc = electronWebrtc()
  wrtc.on('error', err => log('[WRTC]', err))
github beakerbrowser / beaker / app / background-process / networks / dat.js View on Github external
export function setup () {
  // open databases
  dbPath = path.join(app.getPath('userData'), 'Hyperdrive')
  mkdirp.sync(path.join(dbPath, 'Archives')) // make sure the folders exist
  db = level(dbPath)
  archiveMetaDb = subleveldown(db, 'archive-meta', { valueEncoding: 'json' })
  subscribedArchivesDb = subleveldown(db, 'subscribed-archives', { valueEncoding: 'json' })
  ownedArchivesDb = subleveldown(db, 'owned-archives', { valueEncoding: 'json' })
  drive = hyperdrive(db)

  // watch archives for FS changes
  var watcher = chokidar.watch(path.join(dbPath, 'Archives'), { persistent: true, cwd: path.join(dbPath, 'Archives') })
  watcher.on('ready', () => { // wait till ready, otherwise we get an 'add' for each existing file
    watcher.on('add', onArchiveFSChange.bind(null, 'add', 'file'))
    watcher.on('addDir', onArchiveFSChange.bind(null, 'add', 'directory'))
    watcher.on('change', onArchiveFSChange.bind(null, 'change', 'file'))
    // watcher.on('unlink', onArchiveFSChange.bind(null, 'unlink', 'file')) TODO: dat doesnt support deletes yet
    // watcher.on('unlinkDir', onArchiveFSChange.bind(null, 'unlink', 'directory')) TODO: dat doesnt support deletes yet
  })
  app.once('will-quit', () => watcher.close())

  // create webrtc
github beakerbrowser / beaker / app / background-process / networks / dat.js View on Github external
export function setup () {
  // open databases
  dbPath = path.join(app.getPath('userData'), 'Hyperdrive')
  mkdirp.sync(path.join(dbPath, 'Archives')) // make sure the folders exist
  db = level(dbPath)
  archiveMetaDb = subleveldown(db, 'archive-meta', { valueEncoding: 'json' })
  subscribedArchivesDb = subleveldown(db, 'subscribed-archives', { valueEncoding: 'json' })
  ownedArchivesDb = subleveldown(db, 'owned-archives', { valueEncoding: 'json' })
  drive = hyperdrive(db)

  // watch archives for FS changes
  var watcher = chokidar.watch(path.join(dbPath, 'Archives'), { persistent: true, cwd: path.join(dbPath, 'Archives') })
  watcher.on('ready', () => { // wait till ready, otherwise we get an 'add' for each existing file
    watcher.on('add', onArchiveFSChange.bind(null, 'add', 'file'))
    watcher.on('addDir', onArchiveFSChange.bind(null, 'add', 'directory'))
    watcher.on('change', onArchiveFSChange.bind(null, 'change', 'file'))
    // watcher.on('unlink', onArchiveFSChange.bind(null, 'unlink', 'file')) TODO: dat doesnt support deletes yet
    // watcher.on('unlinkDir', onArchiveFSChange.bind(null, 'unlink', 'directory')) TODO: dat doesnt support deletes yet
  })
  app.once('will-quit', () => watcher.close())

  // create webrtc
  wrtc = electronWebrtc()
github VirgilSecurity / virgil-e3kit-js / packages / e3kit-base / src / GroupLocalStorage.ts View on Github external
constructor({ identity, virgilCrypto, leveldown }: GroupLocalStorageConstructorParams) {
        this._encryptionLevel = new VirgilEncryptDown(leveldown, { virgilCrypto });
        const rootLevel = levelup(this._encryptionLevel);
        const identityLevel = sub(rootLevel, identity);
        this._db = sub(identityLevel, 'GROUPS', { valueEncoding: 'json' });
    }
github VirgilSecurity / virgil-e3kit-js / packages / e3kit-base / src / GroupLocalStorage.ts View on Github external
constructor({ identity, virgilCrypto, leveldown }: GroupLocalStorageConstructorParams) {
        this._encryptionLevel = new VirgilEncryptDown(leveldown, { virgilCrypto });
        const rootLevel = levelup(this._encryptionLevel);
        const identityLevel = sub(rootLevel, identity);
        this._db = sub(identityLevel, 'GROUPS', { valueEncoding: 'json' });
    }

subleveldown

Split a levelup database into sublevels with their own keyspace, encoding and events

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Popular subleveldown functions