rabin
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
17420
15
+ Addedarray-index@1.0.0(transitive)
+ Addedd@1.0.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedexecspawn@1.0.1(transitive)
+ Addedext@1.7.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addednode-ninja@1.0.2(transitive)
+ Addedpath-array@1.0.1(transitive)
+ Addedprebuild@4.5.0(transitive)
+ Addedtype@2.7.2(transitive)
+ Addedutil-extend@1.0.3(transitive)
- Removedprebuild@2.9.2(transitive)
Updatedprebuild@^4.1.2