rabin
Advanced tools
Comparing version 1.1.0 to 1.2.0
21
cli.js
#!/usr/bin/env node | ||
var fs = require('fs') | ||
var rabin = require('./')() | ||
var crypto = require('crypto') | ||
var args = require('minimist')(process.argv.slice(2)) | ||
var rabin = require('./')(args) | ||
var offset = 0 | ||
var rs = fs.createReadStream(process.argv[2]) | ||
var rs = fs.createReadStream(args._[0]) | ||
var count = 0 | ||
rs.pipe(rabin).on('data', function (ch) { | ||
console.log(offset += ch.length) | ||
}) | ||
offset += ch.length | ||
count++ | ||
var hash = crypto.createHash('sha256').update(ch).digest('hex') | ||
var data = { | ||
length: ch.length, | ||
offset: offset - ch.length, | ||
hash: hash | ||
} | ||
console.log(JSON.stringify(data)) | ||
}).on('end', function () { | ||
console.error('average', ~~(offset / count)) | ||
}) |
24
index.js
@@ -5,11 +5,14 @@ var stream = require('readable-stream') | ||
var BufferList = require('bl') | ||
var debug = require('debug')('rabin') | ||
module.exports = Rabin | ||
function Rabin () { | ||
if (!(this instanceof Rabin)) return new Rabin() | ||
function Rabin (opts) { | ||
if (!(this instanceof Rabin)) return new Rabin(opts) | ||
this.destroyed = false | ||
this.rabinEnded = false | ||
this.rabin = rabin.initialize() | ||
this.last = 0 | ||
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.nextCb = null | ||
@@ -20,3 +23,3 @@ this.buffers = new BufferList() | ||
this.push(null) | ||
}) | ||
@@ -42,8 +45,7 @@ stream.Duplex.call(this, {objectMode: true}) | ||
}) | ||
var offsets = [] | ||
rabin.fingerprint(this.rabin, bufs, offsets) | ||
for (var i = 0; i < offsets.length; i++) { | ||
var offset = offsets[i] | ||
var size = offset - this.last | ||
this.last += size | ||
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) | ||
@@ -50,0 +52,0 @@ this.buffers.consume(size) |
{ | ||
"name": "rabin", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "node native bindings to a C rabin fingerprinting algorithm", | ||
@@ -9,5 +9,15 @@ "main": "index.js", | ||
}, | ||
"keywords": [ | ||
"rabin", | ||
"cdc", | ||
"chunking", | ||
"fingerprint", | ||
"rolling hash", | ||
"dedupe", | ||
"deduplication", | ||
"rsync" | ||
], | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"install": "prebuild --download", | ||
"install": "prebuild --download && echo \"Installed prebuilt binary successfully.\n\"", | ||
"prebuild": "prebuild" | ||
@@ -21,2 +31,4 @@ }, | ||
"bl": "^1.0.0", | ||
"debug": "^2.2.0", | ||
"minimist": "^1.2.0", | ||
"nan": "^2.1.0", | ||
@@ -23,0 +35,0 @@ "prebuild": "^2.6.2", |
@@ -9,4 +9,6 @@ # rabin | ||
## API | ||
Theres a JavaScript API and an accompanying command-line tool. | ||
## JavaScript API | ||
### `var createRabin = require('rabin')` | ||
@@ -20,3 +22,3 @@ | ||
## Example | ||
## JavaScript Example | ||
@@ -37,1 +39,18 @@ ```js | ||
``` | ||
## CLI API | ||
``` | ||
$ npm install rabin -g | ||
$ rabin myfile.txt --bits=14 --min=8192 --max=32768 # defaults | ||
{"length":12182,"offset":0,"hash":"5df6245b5897336ebf611d7f10fb90eea2d63c5b9ec9ad76dfb1ac72b8249dcb"} | ||
{"length":13190,"offset":12182,"hash":"67d5aaac9cf7b8432cb3c8071d726dc38f1138957c30719f8b166116a90950a1"} | ||
{"length":11609,"offset":25372,"hash":"976a0e3dc43de3abdf50b984a102c5fb7c2550e3dc5e44e4a8f7d4241276683b"} | ||
{"length":10010,"offset":36981,"hash":"7145d10f93ea03e6c8b4dd5ab148e2c3c08f9c71bf71c7559dffdfcef48112c1"} | ||
{"length":13623,"offset":46991,"hash":"76470d5047f9fb31bd75364d90355fdbf913aaa1df934251f43c894f01381f1b"} | ||
{"length":8197,"offset":60614,"hash":"88abce05bc75f72cdafeabd5125eb46fa8f73eab2d75a29076aeb3f99ef35548"} | ||
{"length":16242,"offset":68811,"hash":"08d60789c1e901d6a8e474aeb5de4746af1648e7f3a4ac7a3dba87d9e73fca56"} | ||
{"length":14947,"offset":85053,"hash":"4224e6f4361fa8bdefb9d8e10ebd046e2869af2c44ea7e84c7efaeedd5423b30"} | ||
average 12500 | ||
``` | ||
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
5785372
17
86
54
7
1
+ Addeddebug@^2.2.0
+ Addedminimist@^1.2.0
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)