How to use dat-encoding - 10 common examples

To help you get started, we’ve selected a few dat-encoding 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 joehand / dat-next / lib / commands / clone.js View on Github external
nets({ url: url, json: true }, function (err, resp, body) {
      if (err) return exit(err)
      if (resp.statusCode !== 200) return exit(body.message)
      try {
        opts.key = stringKey(body.url)
        debug('Received key from registry:', opts.key)
        if (opts.key) return createDir(url.split('/').pop(), run) // dirname is name of repo
      } catch (e) {
        console.error(new Error(e))
      }
      exit('Error getting key from registry')
    })
  }
github datproject / hyperdiscovery / index.js View on Github external
leave (discoveryKey) {
    const dKeyStr = datEncoding.toStr(discoveryKey)
    const feed = this._replicatingFeeds.get(dKeyStr)
    if (!feed) return
    if (feed.replicationStreams) {
      feed.replicationStreams.forEach(stream => stream.destroy()) // stop all active replications
      feed.replicationStreams.length = 0
    }
    this._swarm.leave(feed.discoveryKey)
    this.emit('leave', { key: feed.key.toString('hex'), discoveryKey: dKeyStr })
  }
github beakerbrowser / hashbase / lib / archiver.js View on Github external
async _computeArchiveLatestStats (archive) {
    var start = Date.now()
    var release = await lock('archiver-compute-stats')
    const archiveKey = datEncoding.toStr(archive.key)
    const {metadata, content} = archive
    try {
      if (!metadata || !content) {
        // sanity check
        console.error('Had to abort computing archive stats', {archiveKey, metadata: !!metadata, content: !!content})
        return
      }

      // checkout the archive for consistency
      var co = archive.checkout(archive.version)

      // reset all stats
      const st = archive.latestStats
      for (var k in st) {
        st[k] = 0
      }
github beakerbrowser / hashbase / lib / archiver.js View on Github external
archive.replicationStreams.forEach(stream => stream.destroy()) // stop all active replications
      archive.replicationStreams.length = 0
      archive.isSwarming = false
      this.swarm.leave(archive.discoveryKey)
    }

    // done?
    if (opts.download === false && opts.upload === false) {
      if (wasSwarming) {
        console.log(figures.info, 'Unswarming archive', datEncoding.toStr(archive.key))
      }
      return
    }

    // join the swarm
    debounceConsole.log(`${figures.info} Swarming archive`, {timeout: 250, max: 1e3}, datEncoding.toStr(archive.key))
    archive.isSwarming = true
    archive.swarmOpts = opts
    this.swarm.listen(archive.discoveryKey, 0, () => {})
  }
github beakerbrowser / beaker-core / dat / daemon / index.js View on Github external
// keep peerHistory from getting too long
  if (archive.peerHistory.length >= 500) {
    // downsize to 360 points, which at 10s intervals covers one hour
    archive.peerHistory = archive.peerHistory.slice(archive.peerHistory.length - 360)
  }

  // count # of peers
  var totalPeerCount = 0
  for (var k in archives) {
    totalPeerCount += archives[k].metadata.peers.length
  }

  daemonEvents.emit('network-changed', {
    details: {
      url: `dat://${datEncoding.toStr(archive.key)}`,
      peers: getArchivePeerInfos(archive),
      connections: archive.metadata.peers.length,
      totalPeerCount
    }
  })
}
github joehand / dat-next / tests / helpers / index.js View on Github external
function matchDatLink (str) {
  var match = str.match(/[A-Za-z0-9]{64}/)
  if (!match) return false
  var key
  try {
    key = encoding.toStr(match[0].trim())
  } catch (e) {
    return false
  }
  return key
}
github datproject / dat / test / helpers / index.js View on Github external
function matchDatLink (str) {
  var match = str.match(/[A-Za-z0-9]{64}/)
  if (!match) return false
  var key
  try {
    key = encoding.toStr(match[0].trim())
  } catch (e) {
    return false
  }
  return key
}
github datproject / hyperdiscovery / index.js View on Github external
add (feed, opts) {
    if (!feed.key) return feed.ready(() => { this.add(feed) })
    const key = datEncoding.toStr(feed.key)
    const discoveryKey = datEncoding.toStr(feed.discoveryKey)
    this._replicatingFeeds.set(discoveryKey, feed)

    this.rejoin(feed.discoveryKey, opts)
    this.emit('join', { key, discoveryKey })
    feed.isSwarming = true
  }
github dat-land / dat-desktop / lib / dat-manager.js View on Github external
function pause (dat, cb) {
    var key = encoding.toStr(dat.key)
    dat.leaveNetwork()
    dat.stats.emit('update')
    dbPaused.write(key, true, cb)
  }
github dat-land / dat-desktop / lib / dat-manager.js View on Github external
function resume (dat, cb) {
    var key = encoding.toStr(dat.key)
    dat.joinNetwork()
    dat.stats.emit('update')
    dbPaused.write(key, false, cb)
  }

dat-encoding

Encode and decode Dat links

MIT
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis

Popular dat-encoding functions