How to use the rusha.createHash function in rusha

To help you get started, we’ve selected a few rusha 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 PearInc / PearDownloader.js / src / lib / torrent.js View on Github external
)
      isWebSeed ? piece.cancelRemaining(reservation) : piece.cancel(reservation)
      onUpdateTick()
      return
    }

    self._debug(
      'got piece %s (offset: %s length: %s) from %s',
      index, chunkOffset, chunkLength, wire.remoteAddress + ':' + wire.remotePort
    )

    if (!piece.set(reservation, chunk, wire)) return onUpdateTick()

    var buf = piece.flush()

    var hexHash = Rusha.createHash().update(buf).digest('hex');
    if (self.destroyed) return

    if (hexHash === self._hashes[index]) {
      if (!self.pieces[index]) return
      self._debug('piece verified %s', index)

      self.pieces[index] = null
      self._reservations[index] = null
      if (!self.bitfield.get(index)) {                      //pear modified
          self.emit('piecefromtorrent', index);
      }
      self.bitfield.set(index, true)
      self.store.put(index, buf)
      // console.log('self.store.put:'+index);
      self.wires.forEach(function (wire) {
        wire.have(index)
github PearInc / PearDownloader.js / src / lib / torrent.js View on Github external
self.store.get(index, function (err, buf) {
        if (self.destroyed) return cb(new Error('torrent is destroyed'))

        if (err) return process.nextTick(cb, null) // ignore error
        
        var hexHash = Rusha.createHash().update(buf).digest('hex')
        if (self.destroyed) return cb(new Error('torrent is destroyed'))

        if (hexHash === self._hashes[index]) {
          if (!self.pieces[index]) return
          self._debug('piece verified %s', index)
          self._markVerified(index)
        } else {
          self._debug('piece invalid %s', index)
        }
        cb(null)

      })
    }
github PearInc / PearDownloader.js / src / piece-validator.js View on Github external
Validator.prototype.validate = function (data, index) {

    var hash = Rusha.createHash().update(data).digest('hex');
    var equal = hash === this.piecesHash[index];
    if (!equal) {
        console.warn(`[HashValidateError] buffer validate fail ${index} hash ${hash} ref ${this.piecesHash[index]}`);
    }

    return equal;
}
github PearInc / PearDownloader.js / src / lib / webconn.js View on Github external
function WebConn (url, torrent) {
  Wire.call(this)

  this.url = url
  this.webPeerId = Rusha.createHash().update(url).digest('hex')
  this._torrent = torrent

  this._init()
}

rusha

A high-performance pure-javascript SHA1 implementation suitable for large binary data.

MIT
Latest version published 4 years ago

Package Health Score

56 / 100
Full package analysis

Popular rusha functions