Socket
Socket
Sign inDemoInstall

rabin

Package Overview
Dependencies
156
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.5.0

src/rabin_wrap.cc

1

collaborators.md

@@ -6,3 +6,4 @@ ## Collaborators

<table><tbody><tr><th align="left">maxogden</th><td><a href="https://github.com/maxogden">GitHub/maxogden</a></td></tr>
<tr><th align="left">No9</th><td><a href="https://github.com/No9">GitHub/No9</a></td></tr>
<tr><th align="left">mafintosh</th><td><a href="https://github.com/mafintosh">GitHub/mafintosh</a></td></tr>
</tbody></table>

75

index.js

@@ -12,16 +12,15 @@ var stream = require('readable-stream')

if (!opts) opts = {}
stream.Duplex.call(this, {objectMode: true})
stream.Duplex.call(this)
this._readableState.highWaterMark = 16
this._readableState.objectMode = true
this.destroyed = false
this.rabinEnded = false
var avgBits = +opts.bits || 12
var min = +opts.min || 8 * 1024
var max = +opts.max || 32 * 1024
this.rabin = rabin.initialize(avgBits, min, max)
this.rabin = rabin.rabin()
this.rabin.configure(avgBits, min, max)
this.nextCb = null
this.buffers = new BufferList()
this.on('finish', function () {
if (this.buffers.length) this.push(this.buffers.slice(0, this.buffers.length))
this.push(null)
this.rabinEnd()
})
this.pending = []
this.on('finish', this._finish)
}

@@ -31,28 +30,16 @@

Rabin.prototype.rabinEnd = function () {
if (this.rabinEnded) return
this.rabinEnded = true
rabin.end(this.rabin)
Rabin.prototype._finish = function () {
if (this.destroyed) return
if (this.buffers.length) this.push(this.buffers.slice(0, this.buffers.length))
this.push(null)
}
Rabin.prototype._writev = function (batch, cb) {
var self = this
var drained = true
if (this.destroyed) return cb()
var bufs = batch.map(function (b) {
var chunk = toBuffer(b.chunk)
self.buffers.append(chunk)
return chunk
})
var lengths = []
rabin.fingerprint(this.rabin, bufs, lengths)
debug('chunks', lengths)
for (var i = 0; i < lengths.length; i++) {
var size = lengths[i]
var buf = this.buffers.slice(0, size)
this.buffers.consume(size)
drained = this.push(buf)
for (var i = 0; i < batch.length; i++) {
this.buffers.append(batch[i].chunk)
this.pending.push(batch[i].chunk)
}
if (drained) cb()
else this.nextCb = cb
this._process(cb)
}

@@ -69,15 +56,33 @@

Rabin.prototype._write = function (data, enc, cb) {
this._writev([{chunk: data}], cb)
if (this.destroyed) return cb()
this.buffers.append(data)
this.pending.push(data)
this._process(cb)
}
Rabin.prototype._process = function (cb) {
var drained = true
var sizes = []
this.rabin.fingerprint(this.pending, sizes)
this.pending = []
debug('chunks', sizes)
for (var i = 0; i < sizes.length; i++) {
var size = sizes[i]
var buf = this.buffers.slice(0, size)
this.buffers.consume(size)
drained = this.push(buf)
}
if (drained) cb()
else this.nextCb = cb
}
Rabin.prototype.destroy = function (err) {
if (this.destroyed) return
this.destroyed = true
this.rabinEnd()
if (err) this.emit('error', err)
this.emit('close')
}
function toBuffer (buf) {
return Buffer.isBuffer(buf) ? buf : new Buffer(buf)
}
{
"name": "rabin",
"version": "1.4.0",
"version": "1.5.0",
"description": "node native bindings to a C rabin fingerprinting algorithm",

@@ -21,4 +21,4 @@ "main": "index.js",

"test": "echo \"Error: no test specified\" && exit 1",
"install": "prebuild --download && echo \"Installed prebuilt binary successfully.\n\"",
"prebuild": "prebuild"
"install": "prebuild --install",
"prebuild": "prebuild --all --strip --verbose"
},

@@ -34,3 +34,3 @@ "gypfile": true,

"nan": "^2.1.0",
"prebuild": "^2.6.2",
"prebuild": "^4.1.2",
"readable-stream": "^2.0.4"

@@ -37,0 +37,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc